From 5f2efdf442f40a1a2869912405b55519a9b346db Mon Sep 17 00:00:00 2001 From: Bard Date: Tue, 17 May 2022 19:31:13 +0900 Subject: [PATCH] =?UTF-8?q?Add=20=EB=8B=A4=EC=9D=8C-=ED=81=B0-=EC=88=AB?= =?UTF-8?q?=EC=9E=90.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\235\214-\355\201\260-\354\210\253\354\236\220.js" | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git "a/level-2/\353\213\244\354\235\214-\355\201\260-\354\210\253\354\236\220.js" "b/level-2/\353\213\244\354\235\214-\355\201\260-\354\210\253\354\236\220.js" index d9f3503..fe719cb 100644 --- "a/level-2/\353\213\244\354\235\214-\355\201\260-\354\210\253\354\236\220.js" +++ "b/level-2/\353\213\244\354\235\214-\355\201\260-\354\210\253\354\236\220.js" @@ -30,4 +30,15 @@ function solution(n) { const countOne = (str) => { return str.split('').reduce((sum, currentChar) => currentChar === '1' ? sum += 1 : sum, 0) +} + +//정답 3 - prove-ability +function solution(n) { + let i = n; + n = n.toString(2).match(/1/g).length; + while(true) { + i++; + const value = i.toString(2).match(/1/g).length; + if(n === value) return i; + } } \ No newline at end of file