Answer in C# using LINQ.
Enumerable .Range(1, 1000) .Where(i => i % 3 == 0 || i % 5 == 0) .Sum();
Explanation
Enumerable.Range
Where
filter
Sum
Aggregate((acc, n) => acc + n))
reduce
Source & Tests on Github.
short AND legible!
Thanks Joe :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Answer in C# using LINQ.
Explanation
Enumerable.Range
generates a number between 1 & 1000Where
filters records that matches a condition (It's likefilter
in JS)Sum
is a convenience method for summing up a sequence (instead of doingAggregate((acc, n) => acc + n))
, which is equivalent toreduce
in JS)Source & Tests on Github.
short AND legible!
Thanks Joe :)