Tell us what’s happening:
I’m just wanna know what’s the difference between my solution (pretty racoon solution) and the spoiled solution:
Your code so far
//My solution
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
"use strict";
// change code below this line
let first = arr.filter (arr => arr % 1 == 0 && arr > 0)
const squaredIntegers = first.map (arr => arr * arr);
//arr.map (arr => arr * arr);
console.log (squaredIntegers)
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
//Freecodecamp "basic" solution
const squareList = (arr) => {
"use strict";
const squaredIntegers = arr.filter( (num) => num > 0 && num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) );
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions