Introduction

We will be working with Data Structures extensively in this section. We will use JavaScript Arrays a lot. We will discover why a JavaScript Array is not really an Array in the truest sense of the word, but more like a List. You will also learn how to create your own Data Structures in JavaScript. Soon you will be creating and sorting your own Lists in JavaScript.

Let’s do a few warm-up exercises

Write code and unit tests for the functions below.

Swap first two

Create a function:

Given a list :

['apple', 'pear', 'mango', 'banana'];

It should return :

['pear', 'apple', 'mango', 'banana'];

Swap first and last

Create a function:

Given a list :

['apple', 'pear', 'mango', 'banana']

It should return :

['banana', 'pear', 'mango', 'apple']

Know they neighbour

Create a function that:

What is the result of this function? Where does the biggest number ends up?

Use this data :

    [5, 19, 7, 17, 6, 1, 3]

Insights