class Stack {
constructor(stack) {
this.stack = stack || [];
}
push(value) {
this.stack.push(value);
}
pop() {
return this.stack.pop();
}
peek() {
return this.stack[this.stack.length - 1];
}
getLength() {
return this.stack.length
}
}
function tenToTwo(num) {
const stack = new Stack();
let str = ''
while (num > 0) {
stack.push(num % 2);
num = Math.floor(num / 2);
}
const len = stack.getLength();
for (let i = 0; i < len; i++) {
str += stack.pop();
}
return parseInt(str)
}
console.log(tenToTwo(100))