Write Higher Order Arrow Functions a possible new solution?

Write Higher Order Arrow Functions a possible new solution?
0

#1

unfortunately after several months later the solution to this code does not work anymore

why because maybe they updated the challenge
originally(i mean months ago) the first variable looks like this

 const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];

but now they added the -2 at the end of the array

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
  "use strict";
  // below this line is the old solution!!!!!!!!!!!!!
  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);

for this code to work, what i did is just delete that -2 in realNumberArray
since the test said squaredIntegers should be [16, 1764, 36]
and i passed all the test!

if you dont remove the -2 it will log like this [16, 1764, 36, 4] which will fail

my question is did i just cheat?
because im feeling like something is missing


#2

Not sure what you mean by “what i did is just delete that -2 in realNumberArray”. You should not be manually deleting anything. Your original code passed the tests, because the original tests were not robust enough. Your original code should be filtering out negative numbers. That way, no matter what numbers are in an array passed to your function, it will work.

If I pass one million numbers to your function, they only way it would return only squares of positive integers, is if you manually went through and took out the negative numbers. Do you really think that is a workable solution?

You are cheating yourself out of creating a working solution.