Computer >> Computer tutorials >  >> Programming >> Javascript

Calculate the value of (m)1/n in JavaScript


Problem

We are required to write a JavaScript function that takes in two numbers m and n. Our function should calculate and return the value of the following expression −

(m)1/n

Example

Following is the code −

const m = 16;
const n = 4;
const findNthRoot = (m, n) => {
   const power = 1 / n;
   const res = Math.pow(m, power);  
   return res;
};
console.log(findNthRoot(m, n));

Output

Following is the console output −

2