Instructions: Use arrow function syntax to compute the square of only the positive integers (decimal numbers are not integers) in the array realNumberArray
and store the new array in the variable squaredIntegers
.
why does this exercise use the const squaredIntegers declaration twice? Why is my code not working ? it should work. I make sure the element is not a negative number and that it is not a decimal.
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;
squaredIntegers.filter((element) => {
if(element > 0 && element % 2 === 0) {
return Math.sqrt(element) ;
}
}) ;
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);