Challenge 2: Reverse a Stack

Given a stack, reverse the contents of the stack.

Problem Statement

Implement a function that takes a stack, testVariable, and reverses it. Do not use any other extra stack or data structure.

Helper Stack class is provided in the file stack.js. Take a look at the file before implementing your solution. If you want to study stacks in detail, review Interview Refresher Course on Data Structures in Javascript.

Write your code in the space provided in the file index.js.

Input

A variable testVariable that contains a stack.

Output

No explicit output. Our task is to reverse the contents of the stack.

Sample Input

8, 5, 3, 2

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.