Programming Questions

  • Newest
  • Popular Tags
  • Ask Question
  • Longest Word Ruby Issue
    I know I sound like a newb, but I am trying to solve this problem step by step. My first step is to split the string, and so I do: def LongestWord(sen) string = sen.split(" ") return string end just to try and get the words split as a first step (I know I do not to need return string here, but that will be my final step likely) When I do this, the console only returns the last word in the string which is "here", instead of the array ["Argument", "goes", "here"] which is what I am expecting in order to move forward. Have I been using the split function wrong the whole time or is something wrong with Coderbyte?
    eraserface posted this question on 4/12/17 | longest, word, ruby
  • +
  • 1
  • -
  • You're doing it right. Not sure why it's only outputting "here," but remember when you split the string it will return an array. If you want to see the full array just for testing purposes, try using: return string.inspect
  • +
  • 0
  • -
  • For pythong doing a for word in sentence only returns the first element of the list :/.
    Log in to write an answer.