Forked from nextacademy-private/dictionary_sort.rb
Last active
January 12, 2016 17:24
-
-
Save yclim95/844da8bf27d80f751da4 to your computer and use it in GitHub Desktop.
Dictionary Sort
This file contains 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 dictionary_sort(arr) | |
# Your code here to sort the array | |
arr.sort! | |
end | |
# Added a method HERE // for checking if it is a integer | |
def isint(str) | |
return !!(str =~ /^[-+]?[1-9]([0-9]*)?$/) | |
end | |
# ...your code here to initialize the program and take user input | |
arr=[] | |
while true | |
puts "Type a word:(or press enter to finish)" | |
read=gets.chomp | |
break if isint(read) #if is a integer | |
break if read.empty? #if user enter | |
arr<<read | |
end | |
puts dictionary_sort(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment