find power of two digits
Example heading with h2 size
Example heading with h3 size
Following is sample java code.
function transformArray(arr) {
return arr.map((num) => {
const x = Math.floor(num / 10); // Extract the first digit
const y = num % 10; // Extract the second digit
return Math.pow(x, y);
});
}
// Example usage
const inputArray = [43, 24];
const transformedArray = transformArray(inputArray);
console.log(transformedArray); // Output: [64, 16]
function transformArray(arr) {
return arr.map((num) => {
const str = num.toString();
const x = parseInt(str[0]);
const y = parseInt(str[1]);
return Math.pow(x, y);
});
}
// Example usage
const inputArray = [43, 24];
const transformedArray = transformArray(inputArray);
console.log(transformedArray); // Output: [64, 16]
// Polyfill for Math.pow()
function myPow(x, y) {
if (y === 0) {
return 1; // Any number raised to the power of 0 is 1
}
if (y < 0) {
return 1 / myPow(x, -y); // Handle negative exponents
}
let result = 1;
for (let i = 0; i < y; i++) {
result *= x;
}
return result;
}
// Example usage
console.log(myPow(2, 3)); // Output: 8
console.log(myPow(5, 0)); // Output: 1
console.log(myPow(2, -2)); // Output: 0.25