Closed flexdinesh closed 5 years ago
Oh wow, my understanding of .split(x, n)
has been completely off. I suppose I assumed it worked like Java's, where it would stop splitting after n
splits and put the rest in the last element. As it stands, the second parameter seems a bit useless IMO.
Thanks for this, it's a great catch.
As it stands, the second parameter seems a bit useless IMO.
Second param is definitely useless as far as I observed as well. When I remove it, all tests pass. Do you want me to remove the second param as well as part of this PR?
No because it's actually necessary to get it to work as expected.
> (x => x.split(/=(.*)/, 2))('--foo=qux=qox')
[ '--foo', 'qux=qox' ]
> (x => x.split(/=(.*)/))('--foo=qux=qox')
[ '--foo', 'qux=qox', '' ]
We have to have exactly 2 elements for the destructure to work.
Nevermind, TIL that you can have a disproportionate amount of array elements for destructuring. I'm learning so much. I think I'm too used to Python throwing errors when you have wonky things going on.
Still, keep it. I imagine there's some performance benefit, however miniscule.
What a weird API. Javascript is weird.
Great, thank you so much!
Published as 4.1.1
.
Fixes #47