📜  uniqSort - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:00.885000             🧑  作者: Mango

代码示例1
const uniqSort = function (arr) {
  const cache = {};
  const result = [];

  for (let i = 0; i < arr.length; i++) {
    if (!cache[arr[i]]) {
      result.push(arr[i]);
      cache[arr[i]] = true;
    }
  }
  return result.sort((a, b) => a - b);
};

console.log(uniqSort([4, 2, 2, 3, 2, 2, 2]));