Level2 - 이진 변환 반복하기

손대중·2022년 8월 2일
0

문제 설명 및 링크

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>

0개의 댓글