Last active
November 22, 2019 06:01
-
-
Save kenzo0107/d36b644e1f19f69d6ef41382825b9b6a to your computer and use it in GitHub Desktop.
Ruby inject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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