Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created June 20, 2017 06:18
Show Gist options
  • Save kyleshevlin/0352b3a16f97e3672a3058f0b6114542 to your computer and use it in GitHub Desktop.
Save kyleshevlin/0352b3a16f97e3672a3058f0b6114542 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/tuqihev
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function Queue () {
this.storage = ''
}
Queue.prototype.enqueue = function (value) {
if (this.storage.length === 0) {
this.storage = value
} else {
this.storage = value + '***' + this.storage
}
}
Queue.prototype.dequeue = function () {
const items = this.storage.split('***')
const value = items.pop()
this.storage = items.join('***')
return value
}
Queue.prototype.size = function () {
return this.storage.split('***').length
}
const myQueue = new Queue()
myQueue.enqueue('January')
console.log(myQueue.storage)
myQueue.enqueue('February')
console.log(myQueue.storage)
myQueue.enqueue('March')
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)
</script>
<script id="jsbin-source-javascript" type="text/javascript">function Queue () {
this.storage = ''
}
Queue.prototype.enqueue = function (value) {
if (this.storage.length === 0) {
this.storage = value
} else {
this.storage = value + '***' + this.storage
}
}
Queue.prototype.dequeue = function () {
const items = this.storage.split('***')
const value = items.pop()
this.storage = items.join('***')
return value
}
Queue.prototype.size = function () {
return this.storage.split('***').length
}
const myQueue = new Queue()
myQueue.enqueue('January')
console.log(myQueue.storage)
myQueue.enqueue('February')
console.log(myQueue.storage)
myQueue.enqueue('March')
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)</script></body>
</html>
function Queue () {
this.storage = ''
}
Queue.prototype.enqueue = function (value) {
if (this.storage.length === 0) {
this.storage = value
} else {
this.storage = value + '***' + this.storage
}
}
Queue.prototype.dequeue = function () {
const items = this.storage.split('***')
const value = items.pop()
this.storage = items.join('***')
return value
}
Queue.prototype.size = function () {
return this.storage.split('***').length
}
const myQueue = new Queue()
myQueue.enqueue('January')
console.log(myQueue.storage)
myQueue.enqueue('February')
console.log(myQueue.storage)
myQueue.enqueue('March')
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)
console.log(myQueue.dequeue())
console.log(myQueue.storage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment