numbers-words
Version:
numbers-words is a useful package when you are working with numbers. It can converts numbers to words, format numbers and more in the upcoming versions!
12 lines (9 loc) • 394 B
JavaScript
const maxNumber = require("../core/maxNumber.js");
function toRoot(number, root) {
if (isNaN(number) || isNaN(root)) throw new Error("Expected numbers");
if (root === 0) throw new Error("Root cannot be zero");
const result = Math.pow(number, 1 / root);
if (result > maxNumber) throw new Error("Result cannot be greater than " + maxNumber);
return result;
}
module.exports = toRoot;