Sunday, 15 April 2012

Ruby to return my entries alphabetically works for all but my first entry -



Ruby to return my entries alphabetically works for all but my first entry -

this looks like.

word = 'word' words = [] puts 'enter words, man. sick tell em in alphabetical order.' puts 'when your\'re done, press come in without typing before.' puts '' word = gets.chomp while word != '' word = gets.chomp list = list.push word end puts '' puts 'your alphabetically ordered words are:' puts list.sort puts ''

again, works, except first word submit it. hints or help much appreciated.

now work

word = gets.chomp while word != '' list = list.push word word = gets.chomp end

in case, before pushing first word list( when entered while loop), calling 1 time again kernel#gets , assigned word. that's why lost first word, , second 1 started pushing words array.

ruby-on-rails ruby arrays sorting

No comments:

Post a Comment