নেস্টেড ফাংশন ( Nested Function)
function solveEquation(x, n, a) {
function nestedExpression(currentX, currentN) {
if (currentN === 1) {
return Math.pow(currentX, n - 1); // Base case: n = 1
} else {
return Math.pow(currentX, n - 1) * nestedExpression(currentX, currentN - 1);
}
}
function recursiveRoot(currentX, currentN) {
if (currentN === 1) {
return Math.pow(currentX, 1 / n); // Base case: n = 1
} else {
return Math.pow(nestedExpression(currentX, currentN), 1 / n) * recursiveRoot(currentX, currentN - 1);
}
}
return recursiveRoot(x, a);
}
const x = 2; // Replace with the value of x you want to use
const n = 3; // Replace with the value of n you want to use
const a = 4; // Replace with the value of a you want to use
const result = solveEquation(x, n, a);
console.log(`Result: ${result}`);
Last updated