Preparing the way for sort and search.
- What is algorithmic thinking?
- What is an algorithm?
- What is a data structure?
- What data structures have you used?
- How are data structures and algorithms related?
- How do you navigate a data structure?
Write code and unit tests for the functions below.
Clone this repo and run the unit tests with mocha
. The tests needs fixing.
Create a function:
- That takes a list as a parameter.
- Swap the first and the second entry in the list.
- And returns the resulting list.
Given a list :
['apple', 'pear', 'mango', 'banana'];
It should return :
['pear', 'apple', 'mango', 'banana'];
Create a function:
- That takes a list as a parameter.
- And swap the first and the last entry in the list.
- And returns the resulting list.
Given a list :
['apple', 'pear', 'mango', 'banana']
It should return :
['banana', 'pear', 'mango', 'apple']
Create a function that:
- takes a list of numbers;
- loops through the numbers;
- compares each number with its neighbour to the right;
- if a number is bigger than its neighbour on the right, it should swap with its neighbour.
- returns the resulting list.
What is the result of this function? Where does the biggest number ends up?
Use this data :
[5, 19, 7, 17, 6, 1, 3]