DEV Community

Discussion on: Post an Elegant Code Snippet You Love.

Collapse
 
somedood profile image
Basti Ortiz

I've always loved the one-liner for summing up an array of numbers in JavaScript. A lot of people take a hard line on reduce, but I think it looks really nice here.

const sum = numbers.reduce((total, curr) => total + curr);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
franklivania profile image
Chibuzo Franklin Odigbo

One liners are the absolute best!