Calculates the nth root of a given number.
- Use
Math.pow()to calculatexto the power of1 / nwhich is equal to the nth root ofx.
代码实现
const nthRoot = (x, n) => Math.pow(x, 1 / n);
nthRoot(32, 5); // 2
Calculates the nth root of a given number.
Math.pow() to calculate x to the power of 1 / n which is equal to the nth root of x.
const nthRoot = (x, n) => Math.pow(x, 1 / n);
nthRoot(32, 5); // 2