UNPKG

@aegenet/belt-array-duplicates

Version:

Strip duplicates from array / get duplicates of an array.

3 lines (2 loc) 862 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(s,l={}){if(s!=null&&s.length){const t=s.slice(0);if(l.compare&&!l.sorted)throw new Error("Invalid usage: compare function is only available with sorted array.");if(l.sorted){let i=l.compare;if(!i){const e=typeof t[0]=="number"?[]:Object.keys(t[0]);e.length===0?i=(n,r)=>n==r:i=(n,r)=>{let c=!0;for(let f=0;f<e.length;f++){const o=e[f];if((n?JSON.stringify(n[o]):null)!==(r?JSON.stringify(r[o]):null)){c=!1;break}}return c}}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 a(s){const l=[];if(s){const t={};for(let i=0;i<s.length;i++){const e=s[i];e in t?t[e]++:t[e]=0,t[e]===1&&l.push(e)}}return l}exports.getDuplicates=a;exports.stripDuplicates=u; //# sourceMappingURL=index.cjs.map