-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2020-03-19 进制转化 #13
Comments
function mulBase(num, base) {
// code here
const stack = [];
let quotient, remainder;//商 余数
while ((quotient = parseInt(num / base)) !== 0) {
remainder = num % base;
stack.unshift(remainder);
num = quotient;
}
stack.unshift(num % base)
console.log(stack.join(''));
} |
function mulBase(num, base){
const negiativeNum = num < 0
num = negiativeNum ? -num : num
const res = []
do{
res.unshift(num % base)
num = Math.trunc(num / base)
}while (num !== 0)
return negiativeNum ? -res.join('') : res.join('')
} |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
实现一个进制转换函数,不要使用toString
The text was updated successfully, but these errors were encountered: