<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
var firstEqual = [];
var secondEqual = [];
for (var i=0; i<=26; i++) {
firstEqual.push(i);
secondEqual.push(i);
}
var arrayToDedup = [firstEqual, secondEqual];
return _.uniq(arrayToDedup);
var l = [new Set(arrayToDedup)];
return l;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash Uniq | |
Javascript Set |
Test name | Executions per second |
---|---|
Lodash Uniq | 504012.1 Ops/sec |
Javascript Set | 392187.7 Ops/sec |
Let's break down the provided benchmark.
What is tested?
The benchmark tests two approaches to remove duplicates from an array:
Options compared
The benchmark compares the performance of these two approaches:
new Set()
and spreading the array into it)Pros and Cons:
Library
The lodash
library is used in the benchmark. Its purpose is to provide a set of utility functions that can simplify code and make it more efficient, such as the uniq()
function tested here.
Special JS feature or syntax
None mentioned explicitly in this benchmark.
Other alternatives
If you're looking for alternative approaches to remove duplicates from an array, some options include:
filter()
method with a callback function that checks for duplicate values.reduce()
method with a callback function that accumulates unique values.In general, when choosing between these approaches, consider factors such as: