Skip to main content
23 events
when toggle format what by license comment
S Feb 24, 2023 at 23:11 history edited Michael M. CC BY-SA 4.0
Rescued links
S Feb 24, 2023 at 23:11 history suggested tagurit CC BY-SA 4.0
Rescued links
Feb 24, 2023 at 21:08 review Suggested edits
S Feb 24, 2023 at 23:11
S Jan 17, 2019 at 23:35 history suggested Brak CC BY-SA 4.0
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.
Jan 17, 2019 at 19:44 review Suggested edits
S Jan 17, 2019 at 23:35
Jan 17, 2019 at 19:31 comment added Brak I took the liberty of updating the comprehensive jsperf page. I fixed whileLoopAlt2 by adding an initial population of the comparison hash, so now whileLoopAlt2 produces an array with only unique results; it's still pretty fast. Added new test differentiated by an undefined check rather than a falsy, for a faster whileLoopAlt3. And added an even faster(fastest) whileLoopAlt4 which uses null assignments rather than Booleans to save a tiny bit of speed.
Jun 8, 2018 at 23:39 comment added egiray whileLoopAlt function does not removes all duplicates.
Oct 18, 2017 at 6:36 history edited Peter Mortensen CC BY-SA 3.0
Active reading. Dressed the naked links.
May 23, 2017 at 12:18 history edited URL Rewriter Bot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Jun 5, 2015 at 0:24 comment added Stephen S @slickplaid Thanks for setting up the extended perf page. Unless I'm missing something, the "whileLoopAlt2" function doesn't work? It creates a new array containing the first array, and the second array (in reverse order). To avoid confusion I've made another revision that removes the broken function. I also added an additional example: jsperf.com/merge-two-arrays-keeping-only-unique-values/22
Apr 17, 2015 at 13:12 history edited slickplaid CC BY-SA 3.0
Removing last edit because code does not work properly. It does not satisfy the result of deduping the two arrays and combining them.
Apr 17, 2015 at 7:14 comment added doldt @slickpaid Thanks, good job on the extended perf page, very comprehensive!
Apr 16, 2015 at 18:46 history edited slickplaid CC BY-SA 3.0
added one last test case
Apr 16, 2015 at 17:35 history edited slickplaid CC BY-SA 3.0
Added some qualifications to other answers. There are better answers in this list.
Apr 16, 2015 at 16:42 comment added slickplaid @doldt I've addressed your concerns in my answer and added a proper updated test to it as well. Let me know if you agree with those results or not. Also, I added another better result using an associative array.
Apr 16, 2015 at 16:39 history edited slickplaid CC BY-SA 3.0
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.
Apr 16, 2015 at 6:58 comment added doldt @slickplaid the linked tests are empty, and the next revision at jsperf hangs in the while loop.
Apr 15, 2015 at 20:55 comment added slickplaid I agree with your premise @doldt, but disagree with your results. There is a fundamental design flaw with the loop based removal of entries, in that you have to recheck the length of the array after you have removed items, resulting in a slower execution time. A while loop working backwards does not have these effects. Here is an example with removing as many setup variables as I can without changing their original answer too much: jsperf.com/merge-two-arrays-keeping-only-unique-values/19
Apr 14, 2015 at 14:19 comment added doldt There's a flaw in your methodology: you put the creation of array3 into the setup phase, while that cost should only be part of your while-based solution's score. With this 1 line moved, your solution falls to the speed of the for loop based one. I understand that array can be reused, but maybe the other algorithms could benefit too from not having to declare and initialize every necessary building block.
Feb 17, 2015 at 10:26 review Suggested edits
Feb 17, 2015 at 10:44
Sep 4, 2014 at 13:01 history edited slickplaid CC BY-SA 3.0
Missed defining some variables when copying it from my jsperf tests
Aug 4, 2014 at 14:19 history edited slickplaid CC BY-SA 3.0
added results
Aug 4, 2014 at 14:14 history answered slickplaid CC BY-SA 3.0