Skip to content

edesilets/js-objects-stack-challenge

 
 

Repository files navigation

General Assembly Logo

JavaScript Warm-Up: Stack

In computer science, a stack or LIFO (last in, first out) is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the last element that was added. -- Stack (abstract data type), Wikipedia

The goal of this exercise to practice writing prototype methods. As a reminder of how we use prototypes, we've provided started code including a constructor function and one completed prototype method. Your job will be to complete the remaining method.

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Follow the remaining instructions.

Create a custom JavaScript object modeling the stack using a constructor function and a prototype. Starter code has been provided for you in lib/stack.js.

Requirements

  • You should be able to create a new stack with var stack = new Stack();.

  • Your stack should have two methods, push and pop.

    • push adds a new value to the stack's storage and returns the stack itself.
    • pop removes the most recently added value from the stack's storage and returns it.
  • You should not use Array.prototype.push() or Array.prototype.pop().

As you work, you may run grunt test to check your code against these requirements.

Bonus

Pre-fill the stack on instantiation.

var stack = new Stack(1,2,3);
stack.pop(); //=> 3

Which parts of each method are side-effects, and which are the "main" effect?

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%