Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I used to fall for this a lot so now most string comparisons I do something like

  // string contains string against lower case / no whitespace
  cityFromList.indexOf(cityFromPost.trim.toLower()) 
Might help in your case too?


Unfortunately no, 1) you can't trim the whitespace if you're matching cities, 2) matching the cities lowercase opens up too many false positives. At the same time, matching every city with its uppercase equivalent doubles the time requested to build the db but only adds a tiny handful of posts. That's why (for now) I settled with a tradeoff where I catch the uppercase equivalent for the biggest cities only.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: