UNPKG

@aegenet/belt-array-duplicates

Version:

Strip duplicates from array / get duplicates of an array.

3 lines (2 loc) 1.08 kB
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l["@aegenet/belt-array-duplicates"]={}))})(this,function(l){"use strict";function f(n,s={}){if(n!=null&&n.length){const t=n.slice(0);if(s.compare&&!s.sorted)throw new Error("Invalid usage: compare function is only available with sorted array.");if(s.sorted){let i=s.compare;if(!i){const e=typeof t[0]=="number"?[]:Object.keys(t[0]);e.length===0?i=(r,o)=>r==o:i=(r,o)=>{let u=!0;for(let c=0;c<e.length;c++){const a=e[c];if((r?JSON.stringify(r[a]):null)!==(o?JSON.stringify(o[a]):null)){u=!1;break}}return u}}for(let e=t.length-1;e>0;e--)i(t[e],t[e-1])&&t.splice(e,1);return t}else return t.filter((i,e)=>t.indexOf(i)===e)}else return[]}function d(n){const s=[];if(n){const t={};for(let i=0;i<n.length;i++){const e=n[i];e in t?t[e]++:t[e]=0,t[e]===1&&s.push(e)}}return s}l.getDuplicates=d,l.stripDuplicates=f,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=index.umd.js.map