Created
July 3, 2012 17:48
-
-
Save excid3/3041333 to your computer and use it in GitHub Desktop.
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 word_to_number(word) | |
| onesPlace = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] | |
| tensPlace = [nil, 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] | |
| onesPlace.index(word) || tensPlace.index(word) * 10 | |
| end | |
| puts word_to_number('one') | |
| puts word_to_number('two') | |
| puts word_to_number('three') | |
| puts word_to_number('four') | |
| puts word_to_number('five') | |
| puts word_to_number('six') | |
| puts word_to_number('seven') | |
| puts word_to_number('eight') | |
| puts word_to_number('nine') | |
| puts word_to_number('ten') | |
| puts word_to_number('twenty') | |
| puts word_to_number('thirty') | |
| puts word_to_number('forty') | |
| puts word_to_number('fifty') | |
| puts word_to_number('sixty') | |
| puts word_to_number('seventy') | |
| puts word_to_number('eighty') | |
| puts word_to_number('ninety') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment