DEV Community

Cover image for #7DaysJS: Even or Odd
Lautaro Lobo
Lautaro Lobo

Posted on • Originally published at lautarolobo.xyz on

2 1

#7DaysJS: Even or Odd

Welcome to day 2 of 7 Days of JavaScript!

Let’s begin our journey today. We need to write a function that takes an array and gives back two values: one with the sum of all the odd numbers of the array, and other with the sum of all the even numbers on the array.

It can’t be that hard right?

You can read the solution to today’s challenge here.

Top comments (2)

Collapse
 
jenc profile image
Jen Chan

I used a filter for even and odd, then a reduce for both. Probably cost the browser more power eh?

Collapse
 
lautarolobo profile image
Lautaro Lobo

Probably. Usually, for loops are faster, but maybe with larger inputs reduce outworks a for loop...

This post blew up on DEV in 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay