const squareList = arr => {
return arr
.filter(number => number > 0 && number % parseInt(number) === 0)
.map(number => Math.pow(number, 2)) // [25,9]
.reduce((bigN, number) => bigN > number)
};
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers); // true
My purpose is to print the big number in the array to the console after reduce, but I couldn't find how to see the numbers in the string and how to compare them.
Can I do this with reduce?
most likely you want your reduce function to look like this:
reduce((bigN, number) => bigN > number ? bigN : number)
but you can also use Math.max function:
const squareList = arr => {
return Math.max(...arr
.filter(number => number > 0 && number % parseInt(number) === 0)
.map(number => Math.pow(number, 2)))
};