Iterative version of _.unzip #1049

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@almost

As requested in #1047.

This is another option for the implementation of _.unzip. It's a lot faster and not much larger, not as pretty though :)

@jdalton

It now has the sparse issue (may return sparse arrays), again :3

@almost

It shouldn't do. The outer array is built up using push method calls and the inner arrays are created using the Array constructor with the complete length specified. Have I missed something?

@jdalton

Have I missed something?

Yap. Try 1 in _.unzip([[1], [2], [3, 'x']])[1]; // false, should be true
It's also ~29 bytes bigger than the old way that used _.each.

@almost

Ah, again a lack of understanding on my part. I thought Array(x) would produce a non-sparse array but I now see that to make an array non-sparse you need to assign to each element of it.

@almost

Well, as soon as I try and fix that problem it becomes a lot slower:

http://jsperf.com/various-versions-of-unzip

At this point the current version (unzipNoSparse in the jsperf, the one from pr #1047) isn't much slower. So this is making me think we should stick with that version, what do you think @michaelficarra?

@jdalton

@almost you might check out my implementation here.

@jashkenas jashkenas closed this in df2e9e4 Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment