Find the root of a number

Question Implement a function root that calculates the n’th root of a number. The function takes a non-negative number x and a positive integer n and returns the positive n’th root of x within an error of 0.001. Suppose the real root is y, then |y - root(x, n)| < 0.001 Solution Reveal solution /* time complexity: O(n) space complexity: O(1) */ function root(x, n) { if (n === 0) { return 0; } if (n === 1) { return x; } let lower = 0; let upper = x; let guess = (upper + lower) / 2; let tolerance = 0....

1 min · Jesstern Rays