N마리 폰켓몬의 종류 번호가 담긴 배열 nums가 매개변수로 주어질 때, N/2마리의 폰켓몬을 선택하는 방법 중, 가장 많은 종류의 폰켓몬을 선택하는 방법을 찾아, 그때의 폰켓몬 종류 번호의 개수를 return 하도록 solution 함수를 완성해주세요.
function solution(nums) {
const numsLength = nums.length / 2;
const set = new Set(nums);
const arraySet = Array.from(set);
if (numsLength >= arraySet.length) {
return arraySet.length;
} else return numsLength;
}
function solution(nums) {
const numLen = nums.length;
const setLen = [...new Set(nums)].length;
return numLen / 2 >= setLen ? setLen : numLen / 2;
}