Skip to content

Instantly share code, notes, and snippets.

@jjb
Created March 20, 2013 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjb/5201853 to your computer and use it in GitHub Desktop.
Save jjb/5201853 to your computer and use it in GitHub Desktop.
def divisible_by_3?(number)
number%3 == 0
end
def commaifier(number)
reversed = number.to_s.reverse
result = ""
number.to_s.size.times do |i|
result << reversed[i]
result << "," if divisible_by_3?(i+1)
end
result.reverse
end
# > commaifier(25164150)
# => "25,164,150"
# > commaifier(1234567890)
# => "1,234,567,890"
@syntacticsugar
Copy link

:( :( :( :( :(

@syntacticsugar
Copy link

so... concise :( :( :(

@syntacticsugar
Copy link

looks ... rather... nice... :(

@jjb
Copy link
Author

jjb commented Mar 20, 2013

hehehehe

@syntacticsugar
Copy link

@syntacticsugar
Copy link

:( :( :( :(

@jjb
Copy link
Author

jjb commented Mar 20, 2013

yours is shorter than mine...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment