There are ways to do this with array prototype methods: map do replace the existing
for loop and filter to handle your problem here, but you are doing it with loops (we could argue about which is better), so I’ll deal with your approach.
On line 4 you have an
if statement to decide if to push on the square. You are checking if it is positive. What if you could also check if it was an integer and connect it with an
How do you check if something is an integer?
This is a simple JS test for integer:
let a = 1
let b = 2.3
Please let us know if you need more help.