This file contains 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 fisherYates(array) { | |
let i = array.length; | |
let temp, j; | |
while(i) { | |
j = (Math.random() * i--) | 0; // x | 0 gives floor(x) | |
// swap elements i & j | |
temp = array[i]; | |
array[i] = array[j]; |
This file contains 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
// Returns the index of the last array element that satisfies a condition function. Otherwise, returns -1 | |
// Similar to Array.prototype.findIndex, but finds the *last* element by searching from the right | |
// Parameters are exactly the same as findIndex: | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | |
function findLastIndex(array, callbackFn, thisArg) { | |
for (let i = array.length - 1; i >= 0; i--) { | |
if(callbackFn.call(thisArg, array[i], i, array)) { | |
return i | |
} |