Tell us what’s happening:
i dont understand the solution.
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 (X11; CrOS x86_64 12239.92.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.136 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions
lasjorg
September 27, 2019, 7:08pm
2
What specifically about the solution don’t you understand?
Is there any part of the solution you have a question about?
i dont understand the num part can you please help me out
lasjorg
September 27, 2019, 7:36pm
4
Not sure what you mean by the num part?
num
is each number in the array (i.e. the array elements).
const numbersArray = [1, 2, 3, 4];
numbersArray.forEach(num => console.log(num))
// 1, 2, 3, 4
lasjorg
September 27, 2019, 7:50pm
5
This is pretty “spoilery” so I have blurred the code. But as the solution was already posted I think it is OK. I’m not doing it the exact same way but maybe this break down might help.
const numbers = [1, 2, 1.2, 0, -4, 5.5, 8, -3, 10.1];
const positiveNumbers = numbers.filter(num => num > 0);
console.log(positiveNumbers);
// [ 1, 2, 1.2, 5.5, 8, 10.1 ]
const integersOnly = positiveNumbers.filter(num => Number.isInteger(num));
console.log(integersOnly);
// [ 1, 2, 8 ]
const numbersSquared = integersOnly.map(num => Math.pow(num, 2));
console.log(numbersSquared);
// [ 1, 4, 64 ]
Doc links