Sorting Algorithms in Javascript This is just for quick reference does not really talk about CS theory for now. Bubble Sort: let compare = (n1, n2) => n1 - n2; let bubbleSort = (arr, cmp = compare) => { for (let i = 0; i < arr.length; i++) { for (let j = i; j > 0; j--) { if (cmp(arr[j], arr[j - 1]) < 0) { [arr[j], arr[j - 1]] = [arr[j - 1], arr[j]]; } } } return arr; }; Insertion Sort: let inserti