Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers.
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
“use strict”;
// change code below this line
Math.floor
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
// change code below this line
Math.floor
// change code above this line
You can use Array methods like map, filter and reduce to get the desired result.
And the problem is realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]; contains some fraction values which you need to skip and square only the positive integers.
Positive Integers are : 4, 42, 6.
Fractions/Decimal values are 5.6, -9.8, 3.14, 8.34
Thank you, but Math.floor can’t help because this method equal fractions but i must used positive 4, 42, 6.
This my code
// change code below this line
const squaredIntegers = arr.filter((arr) => (Math.pow(arr, 2)));
// change code above this line
But i have error because i used all int, but i know how use only positive int
Hey, please search the forum.
Someone already posted a question about this and you can see the follow up messages.
And you can find a viable solutions to solve this challenge.