Skip to content

Instantly share code, notes, and snippets.

@yclim95
Forked from nextacademy-private/dictionary_sort.rb
Last active January 12, 2016 17:24
Show Gist options
  • Save yclim95/844da8bf27d80f751da4 to your computer and use it in GitHub Desktop.
Save yclim95/844da8bf27d80f751da4 to your computer and use it in GitHub Desktop.
Dictionary Sort
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