Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

คำนวณค่า (m)^(1/n) ใน JavaScript


ปัญหา

เราต้องเขียนฟังก์ชัน JavaScript ที่รับตัวเลขสองจำนวน m และ n ฟังก์ชันควรคำนวณและคืนค่าของนิพจน์:

(m)1/n

ตัวอย่าง

โค้ดด้านล่างนี้

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));

ผลลัพธ์

ผลลัพธ์ในคอนโซลคือ

2