https://school.programmers.co.kr/learn/courses/30/lessons/70129
그냥 풀면 됨.
난 array 가 편해서 array 로 변환해서 풀었는데, 생각해보니 그냥 string 으로 해도 되네;;;
모든 프로그래머스 문제 관련 코드들은 GitHub 링크 에 있음.
<script>
function solution(s) {
let cCount = 0;
let rCount = 0;
s = s.split('');
while (s.length > 1) {
const temp = s.filter(n => n === '1').join('');
rCount += (s.length - temp.length);
s = temp.length.toString(2).split('');
cCount++;
}
return [cCount, rCount];
}
</script>