function solution(n) {
const count = n
.toString(2)
.split("")
.filter((i) => i === "1").length;
while (true) {
n++;
if (
count ===
n
.toString(2)
.split("")
.filter((i) => i === "1").length
)
break;
}
return n;
}
// refactoring
function solution(n) {
const countStrOne = (n) =>
n
.toString(2)
.split("")
.filter((i) => i === "1").length;
const count = countStrOne(n);
while (true) {
n++;
if (count === countStrOne(n)) break;
}
return n;
}
Level
프로그래머스 Lv2
Recruitment