19 - Shaker Sort
A slight adjustment on the classic Bubble Sort algorithm (pictured here).
Lesson and Task Materials:
Visualising the Algorithm:
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)