re: Project Euler #1 - Multiples of 3 and 5 VIEW POST

FULL DISCUSSION
 

Answer in C# using LINQ.

Enumerable
    .Range(1, 1000)
    .Where(i => i % 3 == 0 || i % 5 == 0)
    .Sum();

Explanation

  1. Enumerable.Range generates a number between 1 & 1000
  2. Where filters records that matches a condition (It's like filter in JS)
  3. Sum is a convenience method for summing up a sequence (instead of doing Aggregate((acc, n) => acc + n)), which is equivalent to reduce in JS)

Source & Tests on Github.

 
code of conduct - report abuse