Hacker News new | ask | show | jobs
by jolmg 2270 days ago
My pet-peeve in ruby:

  '//'.split('/') # => [] instead of ['', '', '']
  '/'.split('/') # => [] instead of ['', '']
  ''.split('/') # => [] instead of ['']

  '//'.split('/', -1) # => ['', '', '']
  '/'.split('/', -1) # => ['', '']
  ''.split('/', -1) # => [] instead of ['']
In comparison:

  "".split("/") # => [""] in javascript
  "".split("/") # => [""] in python
1 comments

But if "instead of" means "I expected," doesn't that also mean that Javascript and Python don't do what you expected?
JS & python both have:

'//'.split('/') => [ '', '', '' ] '/'.split('/') => [ '', '' ] '',split('/') => [ '' ]

so they indeed produce what parent expected.