Skip to content

Instantly share code, notes, and snippets.

@will-sklenars
Created April 22, 2015 03:25
Show Gist options
  • Save will-sklenars/7300a3da66552da298b0 to your computer and use it in GitHub Desktop.
Save will-sklenars/7300a3da66552da298b0 to your computer and use it in GitHub Desktop.
first solution for separate_comma(number) challenge
# 1. Initial Solution
def separate_comma(number)
array = []
counter = 0
output_string = ''
# puts number.class
number = number.to_s
# puts number.class
number.reverse!
# puts number.class
array = number.split(//)
array.each do | i |
if counter == 3
output_string << ','
output_string << i.to_s
counter = 1
else
output_string << i.to_s
counter += 1
end
end
puts output_string.class
return output_string.reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment