Published: 07 Jul 2018 › Updated: 07 Jul 2018
Project Euler - Problem 1 | JavaScript one-liner
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:
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ø
- Writing my first code formatter
- Hot Rods at AMCAR Grand Nationals
- Fixing a rocking chair
- Ethereum Classic was just added to Coinbase Pro!
- Exploring Oslo
- 666 followers
- Learning Clojure - Part 5 | Solving Project Euler 02
- Learning Clojure - Part 4 | Finding the nth Fiboncci number
- Project Euler - Problem 1 | JavaScript one-liner
- Learning Clojure - Part 3 | Solving Project Euler 01