Combines the values of one or more arrays, removing duplicates.
const eq = (a, b) => {
return a.name === b.name
}
const v = Arrays.unique([
[ {name:'jane'}, {name:'billy'}, {name:'thom'} ],
[ {name:'molly'}, {name:'jane'}, {name:'sally'}, {name:'thom'}]
], eq);
// [ {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'molly'}, , {name:'sally'} ]
A single array can be provided as well:
const v = Arrays.unique([
{name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'billy'},
], eq);
// [ {name:'jane'}, {name:'billy'}, {name:'thom'} ]
See also:
Combines the values of one or more arrays, removing duplicates.
Compares based on a string representation of object. Uses a Set to avoid unnecessary comparisons, perhaps faster than using a comparer function.
const str = (v) => JSON.stringify(v);
const v = Arrays.unique([
[ {name:'jane'}, {name:'billy'}, {name:'thom'} ],
[ {name:'molly'}, {name:'jane'}, {name:'sally'}, {name:'thom'}]
], str);
// [ {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'molly'}, , {name:'sally'} ]
A single array can be provided as well:
const v = Arrays.unique([
{name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'billy'},
], eq);
// [ {name:'jane'}, {name:'billy'}, {name:'thom'} ]
By default uses JSON.toString() to compare values.
See also:
Combines the values of one or more arrays, removing duplicates.
By default compares values based on a JSON string representation.
Param: arrays
Array (or array of arrays) to examine
Param: toString
Function to convert values to a string for comparison purposes. By default uses JSON formatting.
Returns