DEV Community

Discussion on: Can you simplify this code for the guy?

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan • Edited

The ternary is unnecessary. The modulo operator already returns a boolean expression, so it's redundant. It's like saying "true or false ? true: false."

Here's a simplified version:

numbers.forEach(num => console.log(num % 2 === 0));
Collapse
 
joelbonetr profile image
JoelBonetR 🥇

totally agree 😆
I took the other answer as start point only to figure out why the OP said it's incomplete, so i used a foreach for testing purposes and commented it "as is" 😅