Created
April 22, 2015 03:25
-
-
Save will-sklenars/7300a3da66552da298b0 to your computer and use it in GitHub Desktop.
first solution for separate_comma(number) challenge
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
| # 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