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 coded
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/78.0.136 Chrome/72.0.3626.136 Safari/537.36.
@ilenia I really appreciate the explanation, I’ve been trying to understand every single line and this was super helpful. Hope you don’t mind explaining one more thing (I’m a beginner and can’t wrap my head around this specific part).
const squareList = (arr) => {
In the first line we assign the array to realNumberArray
How is that we don’t assign arr to be equal to this array [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]; and it is used in the code?
I realize this might be a very basic question but I can’t find the explanation.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
I’m having the same comprehension problem. I accidentally posted a similar question before landing on this one. My problem is in understanding how % works and what exactly it’s doing.
5.2 % parseInt(5.2)===0
is parseInt splitting 5.2 into 5 and 0.2? Or is it just removing the 5? In this explanation the result is that parseInt is comparing 0.2 ===0 How is it ending up with that comparison?
parseInt makes an integer from its argument, so it keeps the part before the decimal separator
% is the reminder operator, makes a division and returns the reminder.
you have the operation 5.2 % 5, if it was a division the result would be 1 point something, with reminder operator it stops the division at a whole result, so the result of the division is 5.2 / 5 = 1 reminder 0.2
the operator then returns the reminder
I suggest you read the documentation on those things:
that does much more sense - even using num % 1 === 0 does much more sense, but that is the answer provided in the guild, and people asks clarifications