Hello, i have trouble with this rule:
squaredIntegers should be [16, 1764, 36]
Link: https://beta.freecodecamp.org/en/challenges/es6/write-higher-order-arrow-functions
My code:
"use strict";
const realNumberArray = [ 4, 5.6, -9.8, 3.14, 42, 6, 8.34 ];
let squaredIntegers = realNumberArray.filter((squareSupZero) => squareSupZero >= 0 );
squaredIntegers = realNumberArray.map((squareSupZero) => squareSupZero >=0 );
console.log( squaredIntegers );
It’s maybe a bug with the “const”… I tried changing it to let and even var but i have the same error.
Have a nice day.
ps: if you think it would be better to go to the chat room and ask, tell me !
1 Like
Hello, i really thanks you for your help.
I miss readed the exercice. I didn’t see “to compute the square”. And i think using the term ‘float’ would be better than “fractions are not integers”. More direct and easy to understand for foreigners (my thought).
By looking over internet how to identify float from integer, i used this ( x % 1 === 0):
"use strict";
const realNumberArray = [ 4, 5.6, -9.8, 3.14, 42, 6, 8.34 ];
let squaredIntegers = realNumberArray.filter((integer) => integer % 1 === 0 );
squaredIntegers = squaredIntegers.map((square) => square*square );
console.log( squaredIntegers );
Is there a better way to do it directly ? like with Filter itself ? or other already made function ?
Thanks you again.
2 Likes
Ok, thanks you ! The use of [] is very special.
1 Like
Ah yes of course
Nicely done.
where is the chat room. i’m new here
I did it this way, but it wants the squaredIntegers to be a const… How would I go about making squaredIntegers a const?
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
"use strict";
// change code below this line
let squaredIntegers = arr.filter(num => Number.isInteger(num));
squaredIntegers = squaredIntegers.map(square => square*square);
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
3 Likes
Figured it out after a bit of reading. Just had to go straight into the .map function.
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
"use strict";
// change code below this line
const squaredIntegers = arr.filter(num => Number.isInteger(num)).map(square => square*square);
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
10 Likes
Thats how I solved it too!
a similar solution 
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
"use strict";
// change code below this line
const squaredIntegers = [];
arr.map( num => {
if(Number.isInteger(num)){
squaredIntegers.push(num * num);
}
})
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
3 Likes