https://programmers.co.kr/learn/courses/30/lessons/1845
function solution(nums) {
var answer = [];
var max = nums.length / 2;
for(let i = 0; i < nums.length; i++) {
if(answer.length < max) {
if(!answer.includes(nums[i])) {
answer.push(nums[i]);
}
}
}
return answer.length;
}
const solution = nums => {
let answer = [];
const max = nums.length / 2;
nums.map(num => (
answer.length < max && !answer.includes(num) ? answer.push(num) : num
));
return answer.length;
}
//다른 사람 풀이
const solution = nums => {
let answer = [...new Set(nums)],
limit = nums.length / 2;
return answer.length > limit ? limit : answer.length;
}