EXERCISE · AlgoCasts

Stack

Create a stack data structure. The stack should be a class with methods 'push', 'pop', and 'peek'. Adding an element to the stack should store it until it is removed.

4 testsAlgoCastsGPL-3.0exercise 16 of 26

Directions

Directions

Create a stack data structure. The stack should be a class with methods 'push', 'pop', and 'peek'. Adding an element to the stack should store it until it is removed.

Examples#

JS
const s = new Stack();s.push(1);s.push(2);s.pop(); // returns 2s.pop(); // returns 1

Try it first#

Copy the stub, make the 4 tests pass on your machine, then open the solution. The reveal is remembered per page in this browser.

JSexercises/stack/index.js
class Stack {} module.exports = Stack;

See also