Created
June 20, 2017 06:18
-
-
Save kyleshevlin/0352b3a16f97e3672a3058f0b6114542 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/tuqihev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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