
Use 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);
// Examples
nthRoot(32, 5); // 2
Source
https://www.30secondsofcode.org/js/s/nth-root