Hacker News new | ask | show | jobs
by parennoob 3752 days ago
As I said, until it hits some kind of edge case. Again, I'm not trying very hard here, but this oneliner doesn't give the expected output if your sentence has a string like "æsir".

  irb> @sentence = "\u00e6sir are gods"
  => "æsir are gods"

  irb> @sentence = @sentence.split(' ').map!{|x| x = x[0..0].upcase << x[1..-1]}.join(' ')
  => "æsir Are Gods"
(Expected output being "Æsir Are Gods")

If you want to understand why this is failing, the code I gave above will make it way simpler. Of course, viewpoints differ – you might claim that troubleshooting it is only a job for "professionals".

1 comments

Its all a matter of what gets the algorithm into your head most clearly. If extra names and steps do it for you, then cool. But at some point extra names get in the way - they can suggest the wrong thing (what was intended but not what is actually happening). That's how troubleshooting goes astray.