Last active
February 12, 2020 16:43
-
-
Save Giagnus64/bb747da4d9168d66c3866a0683c78611 to your computer and use it in GitHub Desktop.
Array implementation of a stack using push/pop
This file contains hidden or 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
| //STACK = LAST IN FIRST OUT | |
| const stack = []; | |
| stack.push({"Willow Rosenberg": "A"}); | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" }] | |
| stack.push({"Xander Harris": "C"}); | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" }, { "Xander Harris": "C" }] | |
| stack.push({"Cordelia Chase": "B+"}); | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" },{ "Xander Harris": "C" },{ "Cordelia Chase": "B+" }] | |
| stack.push({"Buffy Summers": "B"}); | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" },{ "Xander Harris": "C" },{ "Cordelia Chase": "B+" },{ "Buffy Summers": "B" }] | |
| //REMOVAL | |
| let firstOut = stack.pop(); | |
| // { "Buffy Summers": "B" } | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" },{ "Xander Harris": "C" },{ "Cordelia Chase": "B+" }] | |
| firstOut = stack.pop(); | |
| //{"Cordelia Chase": "B+"} | |
| console.log(stack); | |
| //[{ "Willow Rosenberg": "A" }, { "Xander Harris": "C" }] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment