Implement a Dynamic Array

Clone the project from the starter.

Now that you've gone a bit deeper into understanding how arrays work in JavaScript, let's try to implement one on your own! Recall that the Array class includes the following:

  • Properties:
    • length
  • Methods:
    • read
    • push
    • pop
    • shift
    • unshift
    • indexOf
    • resize

For these exercises, you may not use any built-in JavaScript array methods.

You may use:

  • new Array(size) to create new storage arrays
  • arr[i] to read/write elements by index

You must call resize whenever the size of your array exceeds the capacity.

To run tests

  1. Clone the starter and navigate to dynamic-array
  2. npm install to install the test packages
  3. npm test to run tests
  4. Implement code in dynamic-array.js until all tests are green.

Tip: Reading test specs is key to understanding the problem.

Learning Goals

  • Identify the mechanics and complexity of adding and removing elements from an Array
  • Solve the memory equation to retrieve data from an array
  • Describe the resizing property of Dynamic Arrays and why it's needed
  • Implement a Stack data structure using an array
  • Select an Array or Stack when they are the appropriate tool for solving a problem