Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Stack Class

Object-Oriented Programmingmedium

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 226: ES6 Classes

Define a `Stack` class with `push` and `pop`, and implement `stackOps(values)` that pushes every value then pops them all, returning the popped values in order.

Sample tests

Input: stackOps([1,2,3])
Output: [3,2,1]
Input: stackOps([])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Confusing stack (LIFO) order with queue order.

Learning resources

  • MDN: Classes
Approach & explanation (try first)

A stack is last-in-first-out, so pushing then popping all items yields them reversed.

Loading...
⌘/Ctrl + Enter

Run your code to see results.