A comment pointed out that one of my setup variables was causing my loop to pull ahead of the rest, because it didn't have to initialize an empty array to write to. I agree with that, so I've rewritten the test to even the playing field, and included an even faster option.
This change corrects the "uniqueifying" behavior by populating initial assoc hash with the keys from the first array. It doesn't _appear_ to hurt the speed too much. I've also updated it to not use a falsy check for a speed boost, and not use booleans for a little additional speed bump.
Peter Mortensen
- 31.3k
- 22
- 109
- 132
Removing last edit because code does not work properly. It does not satisfy the result of deduping the two arrays and combining them.
slickplaid
- 1.4k
- 1
- 17
- 21
Added some qualifications to other answers. There are better answers in this list.
slickplaid
- 1.4k
- 1
- 17
- 21
fixed issue with my original answer as one of the comments had pointed out. Added a second, faster result with the use of an associative array rather than indexOf on an basic array.
slickplaid
- 1.4k
- 1
- 17
- 21
slickplaid
- 1.4k
- 1
- 17
- 21