Tell us what’s happening:
i need to know solution of given code :
how can we get squaredIntegers [16, 1764, 36]??
Your code so far
const realNumberArray= [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
“use strict”;
const squaredIntegers= array.filter(function(e) {return e%2 === 0;});
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
First, you need to filter positive integers and then you need to calculate their square.
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
"use strict";
// change code below this line
const squaredIntegers = arr.filter(item => item > 0 && Number.isInteger(item)).map(item => item**2);
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);