+ 4
How to calculate for n root of a number in JS?
For example : the n root of 32 where n = 5 The answer is 2, because 2Ă2Ă2Ă2Ă2 = 32. If square root, we can use the Math.sqrt, how about something like the example above?
4 Answers
+ 11
You can use Math.pow, because the root is the inverse of the power, so for example Math.pow(32,1/5) should give you 2.
+ 2
well I was interested to solve this problem by myself. Here's my attempt
https://code.sololearn.com/W3o81D15Sava/?ref=app
+ 2
The only problem is decimal numbers. I used Math.floor there, so my function could return something (regardless inexact value). But works fine with integers.
+ 2
It throws error sometimes btw "Maximum call stack size exceeded". Well it's definitely worst solution ever. I'm just not that good with JS yet đ€Ł