January 2018
Intermediate to advanced
332 pages
7h 36m
English
First, let's create the Quicksort class, which will sort the elements based on the pivot as the first element in the set passed. Let's create a file called quick.js under the sort folder:
class Quick { simpleSort(data) { // if only one element exists if(data.length < 2) { return data; } // first data point is the pivot const pivot = data[0]; // initialize low and high values const low = []; const high = []; // compare against pivot and add to // low or high values for(var i = 1; i < data.length; i++) { // interchange condition to reverse sorting if(data[i].pages > pivot.pages) { low.push(data[i]); } else { high.push(data[i]); } } // recursively sort and concat the // low values, pivot and high values return ...
Read now
Unlock full access