// function Stack() {
// let items = []
// this.push = function (element) {
// items.push(element)
// }
// this.pop = function () {
// items.pop()
// }
// this.peek = function () {
// return items[items.length - 1]
// }
// this.isEmpty = function () {
// return items.length === 0
// }
// this.size = function () {
// return items.length
// }
// this.clear = function () {
// items = []
// }
// this.print = function () {
// console.log(JSON.stringify(items))
// }
// }
// ES6
class Stack {
constructor() {
this.items = []
}
push(element) {
this.items.push(element)
}
pop() {
this.items.pop()
}
peek() {
return this.items[items.length - 1]
}
isEmpty() {
return this.items.length === 0
}
size() {
return this.items.length
}
clear() {
this.items = []
}
print() {
console.log(this.items.toString())
}
}
function divideBy2(decNumber) {
var remStack = new Stack(),
rem,
binaryString = ''
while(decNumber > 0) {
rem = Math.floor(decNumber % 2)
remStack.push(rem)
decNumber = Math.floor(decNumber / 2)
}
while(!remStack.isEmpty()) {
console.log(JSON.stringify(remStack))
binaryString += (remStack.pop()).toString()
}
return binaryString
}
// console.log(divideBy2(233))