去重

84 阅读1分钟
function noRepeat(arr: any[]) {
  const hash = new Map();

  arr.forEach((item) => {
    if (hash.has(item)) return;
    hash.set(item, true);
  });

  return [...hash.keys()];
}

const arr = noRepeat([1, 1, 1, 1, 2, 2, 2, 3]);
console.log(arr);