This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pivotHelper(array, start = 0, end = array.length) { | |
| let pivotValue = array[start] | |
| let pivotIndex = start | |
| for (let i = start + 1; i < end; i++) { | |
| if (pivotValue >= array[i]) { | |
| pivotIndex++ | |
| [array[pivotIndex], array[i]] = [array[i], array[pivotIndex]] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mergeSort(array) { | |
| for (var b = 1; b < array.length; b *= 2) { | |
| let a = [] | |
| for (var i = 0; i < array.length; i += 2 * b) { | |
| a = a.concat( | |
| merger( | |
| array.slice(i, i + b), | |
| array.slice(i + b, i + 2 * b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function insertionSort(array) { | |
| for (var i = 1; i < array.length; i++) { | |
| for (var j = i; j > 0 && !(array[j] > array[j - 1]); j--) { | |
| if (array[j] < array[j - 1]) { | |
| [array[j - 1], array[j]] = [array[j], array[j - 1]] | |
| } | |
| } | |
| } | |
| return array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function selectionSort(array) { | |
| for (var i = 0; i < array.length - 1; i++) { | |
| let vMin = array[i] | |
| let iMin = i | |
| for (var j = i + 1; j < array.length; j++) { | |
| if (vMin > array[j]) { | |
| vMin = array[j] | |
| iMin = j | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bubbleSort(array) { | |
| for (var i = 0; i < array.length; i++) { | |
| for (var j = 1; j < array.length - i; j++) { | |
| if (array[j - 1] > array[j]) { | |
| [array[j - 1], array[j]] = [array[j], array[j - 1]] | |
| } | |
| } | |
| } | |
| return array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countdown(num) { | |
| let array = [] | |
| function helperRecursive(n) { | |
| array.push(n) | |
| if (n === 0) return | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fact(n) { | |
| if (n === 1) | |
| return 1 | |
| return n * fact(n - 1) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function recursive(n) { | |
| if (n === 0) | |
| return | |
| // recursive call with same input | |
| recursive(n) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function recursive(n) { | |
| // missing return inside Base Case | |
| if (n === 0) | |
| console.log(n) | |
| recursive(n - 1) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function recursive(n) { | |
| // missing Base Case | |
| recursive(n - 1) | |
| } |