Just map over the array and do Math.pow(int,power)
but multiplication is faster so do value * value
in the .map
function
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]; // your array
const squares = realNumberArray.filter(x => x > 0 && Number.isInteger(x)); // your filter function
const squared = squares.map(val => val*val) // map and do val*val to get an array of elements of val*val
console.log(squared) // log it
Your code becomes
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
"use strict";
const squaredIntegers = realNumberArray.filter(x => x > 0 && Number.isInteger(x));
const squared = squaredIntegers.map(val => val*val)
return squared;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
solved How to square integers inside an array?