function solution(n) {
var answer = n + 1;
while (true) {
let oneLength = n
.toString(2)
.split("")
.filter((a) => a === "1").length;
let resultLength = answer
.toString(2)
.split("")
.filter((a) => a === "1").length;
if (oneLength === resultLength) {
break;
}
answer++;
}
return answer;
}
toString(2)으로 이진수로 변환->split을 통해 배열로 하나씩 쪼개 저장->filter함수로 1을 가지는 값만 찾아서 배열로 다시 리턴->그 배열의 길이 저장
n+1을 증가시켜가며 1의 개수를 비교, 같아지면 반복문 탈출