function Stack() {
let __items = [];
this.push = function (element) {
__items.push(element);
}
this.pop = function () {
return __items.pop();
}
this.peek = function () {
return __items[item.length - 1];
}
this.isEmpty = function () {
return __items.length === 0
}
this.size = function () {
return __items.length
}
this.clear = function () {
__items = []
}
this.print = function () {
console.log(__items.toString())
}
}
let stack= new Stack();
console.log(stack.isEmpty());
stack.push(8);
stack.push(10);
function divideBy2 (decNumber) {
let remStack = new Stack();
let rem, binaryString = '';
while (decNumber > 0) {
rem = Math.floor(decNumber % 2);
remStack.push(rem);
decNumber = Math.floor(decNumber / 2);
}
while (!remStack.isEmpty()) {
binaryString += remStack.pop().toString();
}
return binaryString;
}
console.log(divideBy2(79))
console