Skip to content

Instantly share code, notes, and snippets.

@giruzou
Created September 29, 2018 04:49
Show Gist options
  • Select an option

  • Save giruzou/1b17ff6fb9e2dd5fb01ff26f6771d71b to your computer and use it in GitHub Desktop.

Select an option

Save giruzou/1b17ff6fb9e2dd5fb01ff26f6771d71b to your computer and use it in GitHub Desktop.
Ruby配列の余りの合計 ref: https://qiita.com/DrqYuto/items/4cef67bca6d8569af101
def mod_sum(array, n)
return array.length > 0 ? array.map{ |number| number % n }.inject{ |sum, number| sum + number } : 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment