Created
March 12, 2018 07:11
-
-
Save amorfati0310/c162df0b738e8aa69583845a8387e5ef to your computer and use it in GitHub Desktop.
진수변환
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 마우스를 만들어보기 | |
// 1. 원리를 이해하자 | |
// 2. 모양 설계 | |
// 3. 볼 마우스에 필요한 볼 만들기 ......... | |
const getResult = (number, digits) => { | |
let result = []; | |
while (number > 0) { | |
result.unshift(number % digits); | |
number = parseInt(number / digits); | |
} | |
result = Number(result.join("")); | |
return result; | |
}; | |
const equal = (number, digits) => { | |
return getResult(number, digits) === +number.toString(digits); | |
}; | |
const equals = (arr, digits) => { | |
const result = arr.every(number => { | |
return equal(number, digits); | |
}); | |
return result; | |
}; | |
console.log(getResult(16, 8)); | |
console.log(equals([16, 20, 8, 2], 8)); | |
(function(n) { | |
console.log(n); | |
})(3); | |
// console.log(equal(1632, 8)); | |
// console.log(equal(1346, 8)); | |
// console.log(equal(55556, 8)); | |
// console.log(equal(19823496, 8)); | |
// console.log(equal(92346, 8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment