Compute Cube Root in JavaScript

Posted by yhuang
Public (Editable by Users)
JavaScript
None
Edit
console.log(Math.cbrt(-1));
// expected output: -1

console.log(Math.cbrt(1));
// expected output: 1

console.log(Math.cbrt(Infinity));
// expected output: Infinity

console.log(Math.cbrt(64));
// expected output: 4

Math.cbrt(NaN); // NaN
Math.cbrt(-1); // -1
Math.cbrt(-0); // -0
Math.cbrt(-Infinity); // -Infinity
Math.cbrt(0); // 0
Math.cbrt(1); // 1
Math.cbrt(Infinity); // Infinity
Math.cbrt(null); // 0
Math.cbrt(2);  // 1.2599210498948732