[프로그래머스] 폰켓몬


function solution(nums) {
  let answer = [];
  let chooseNum = nums.length / 2;

  for (let i = 0; i < nums.length; i++) {
    if (answer.includes(nums[i]) === true) {
      continue;
    } else {
      answer.push(nums[i]);
    }
  }

  return answer.length <= chooseNum ? answer.length : chooseNum;
}

좋은 웹페이지 즐겨찾기