In the code below, power
isn't a pure function (uses two global variables), how can i convert it into a pure function with just one input array
as parameter?
const multiplyByFour = function (array) {
return array.map((item) => item * 4);
};
const sumElements = function (array) {
return array.reduce((total, num) => {
return total + num;
});
};
function power(arr) {
let lengthArray = arr.length;
let value = sumElements(multiplyByFour(arr));
return Math.pow(value, lengthArray);
}
console.log(power([3, 4, 2]));