• Post Reply Bookmark Topic Watch Topic
  • New Topic

3 lines i dont understand  RSS feed

 
Dmitri Makovetskiy
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my task is..:
1) create a dictionary. the user should feed words to both languages till the word "enough" is typed in.
2) write a sentence in hebrew.
3)seperate teh words in teh senentece and compare them to the words in teh dictionary i previously created

i practiced rewriting the code myself, i re-wrote everything successfully . apart from those lines.. i dont know what they mean,,please help.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, when you were "playing computer" with the pen and paper, what did you come up with?

Maybe start by breaking down each of the conditionals: what do each of the following mean?

1) index < sentence.length()
2) sentence.charAt(index) == ''
3) sentence.charAt(index) != ''

As to whether or not it works with only one of those, when you commented one out, what happened?

(And I'm not sure what "practiced rewriting the code myself" means; if you re-wrote it yourself, why would you write two lines you didn't understand, and how did you know to write them?)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code:is essentially identical, and should be refactored into a single method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!