Tracks unique values. Returns true if value is unique. Alternatively: uniqueInstances
const t = unique();t(`hello`); // truet(`hello`); // false Copy
const t = unique();t(`hello`); // truet(`hello`); // false
Uses JSON.stringify to compare anything which is not a string.
Provide a custom function to convert to string to track uniqueness for more complicated objects.
const t = unique(p => p.name);t({ name:`John`, level:2 }); // true// Since we're judging uniques by name onlyt({ name:`John`, level:3 }); // false Copy
const t = unique(p => p.name);t({ name:`John`, level:2 }); // true// Since we're judging uniques by name onlyt({ name:`John`, level:3 }); // false
Return function throws an error if value is null or undefined.
value
Tracks unique values. Returns true if value is unique. Alternatively: uniqueInstances
Uses JSON.stringify to compare anything which is not a string.
Provide a custom function to convert to string to track uniqueness for more complicated objects.
Return function throws an error if
value
is null or undefined.