Tell us what’s happening:
Can someone explain me this code line:
const squaredIntegers = arr.filter( (num) => num > 0 && num % parseInt(num) === 0).map ( (num) => Math.pow(num,2) );
I dont understand why the solution have && num % parseInt(num)===0
and the function (num) =>Math.pow(num,2)
What does Math.pow doing? and the if case && num % parseINt(num)===0
is everytime time true or not? example with integer 4.2: parseInt(4.2) makes from 4.2 into a Int 4. and 4 % 4 === 0 is true. So by any number, dont matter which number i take, the solution in this part is always true. so why we have this if case here?
Thanks and sorry for my bad english
Your code so far
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( (num) => num > 0 && num % parseInt(num) === 0).map ( (num) => Math.pow(num,2) );
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions