18 - Insertion Sort
π€ How many ways can you sort a complete mess of numbers? Is there one fastest method?Β
In the next set of lessons we will code and compare some common sorting algorithms and then dive further into algorithm design.
π§ The Lesson:
Discussion Questions (in Google Classroom)
Visualising the Algorithm:
xSortLab - Visualization of Sorting
The library.js file you have been using for round() and randInt() has been updated. The functions are documented inside the code file. Most of the added functions are to help with creating test data.
Arrays in JS are passed & copied by reference
What does this mean - by reference?
It means that when you try to make a copy or pass an array into a function, it does not actually duplicate every item in the array to create separate arrays. It makes a link or shortcut to the array.
Example
let origSheeps = ['π', 'π'];
let sheeps2 = origSheeps;
sheeps2.push('πΊ');
console.log(sheeps2);
Β Β // [ 'π', 'π', 'πΊ' ]
console.log(origSheeps);
Β Β // [ 'π', 'π', 'πΊ' ]
π± , our original sheeps have changed?!
(source)