Skip to content

Instantly share code, notes, and snippets.

@dubistdu
Last active February 1, 2019 20:07
Show Gist options
  • Save dubistdu/d64f8a4c560e8507dfd0efd234cbc373 to your computer and use it in GitHub Desktop.
Save dubistdu/d64f8a4c560e8507dfd0efd234cbc373 to your computer and use it in GitHub Desktop.
Multiples of 3 or 5

*JS

const solution = (number) => {
  return (number < 1 ? 0 : [...Array(number).keys()].filter(num => num % 3 == 0 || num % 5 == 0).reduce((a,b) => a+b));
}

*ruby

def solution(number)
  (1...number).select { |num| num % 3 == 0 || num % 5 == 0 }.sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment