Skip to content

Instantly share code, notes, and snippets.

@kenzo0107 kenzo0107/divmod_inject.rb
Last active Nov 22, 2019

Embed
What would you like to do?
Ruby inject
def div_inject(r)
[10_000, 5_000, 2_000, 1_000, 500, 100, 50, 10, 5, 1].inject(r){|(*a, r), d|
a + r.divmod(d)
}
end
p div_inject(123_456) # [12, 0, 1, 1, 0, 4, 1, 0, 1, 1, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.