Skip to content

Instantly share code, notes, and snippets.

@kaochenlong
Last active April 16, 2016 01:50
Show Gist options
  • Save kaochenlong/fad0bd1c37b64f7e7ce43a7b18d582a2 to your computer and use it in GitHub Desktop.
Save kaochenlong/fad0bd1c37b64f7e7ce43a7b18d582a2 to your computer and use it in GitHub Desktop.
def add_zero(n, digit = 0)
"#{"0" * digit}#{n}"[-digit..-1]
end
puts add_zero(3, 5) #=> 00003
puts add_zero(13, 8) #=> 00000013
puts add_zero(43, 10) #=> 0000000043
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment