본문 바로가기

Programming/데일리 알고리즘

(210519:BTB) Lesson 6. Distinct

유형 : 정렬 

풀이 : Set 객체는 중복된 값을 허용하지 않는다는 것을 이용하여 풀 수 있다. 

 

function solution(A) {
  const array = A.slice();

  let newSet = new Set();
  for (let item of array) {
    newSet.add(item);
  }

  return newSet.size;
}

console.log(solution([2, 1, 1, 2, 3, 1]));