Øyvind Sæbø avatar

Project Euler - Problem 1 | JavaScript one-liner

oyvindsabo

Published: 07 Jul 2018 › Updated: 07 Jul 2018Project Euler - Problem 1 | JavaScript one-liner

Project Euler - Problem 1 | JavaScript one-liner

Project Euler 001 One Line.jpg

A few days ago, in my post Learning Clojure - Part 2 | Writing a Basic Function, I solved the first Project Euler problem in JavaScript, as preparation to solve that very same problem in Clojure.

My JavaScript solution is included below:

let sum = 0
for (let i = 0; i  233168

In that same post, I also wrote that had I spent a little more time, I could probably come up with a neat one-liner as well.

And so I did:
console.log(Array.from(Array(1000).keys()).filter(x => x%3 === 0 || x%5 === 0).reduce((a, b) => a + b));

// => 233168

Leave Project Euler - Problem 1 | JavaScript one-liner to:

Written by

Art // Cars // Programming

Read more #programming posts


Best Posts From Øyvind Sæbø

We have not curated any of oyvindsabo's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Øyvind Sæbø