INNER CODE UNIT · TypeScript
shuffleArray
mifi/instauto · src/index.ts:199
function shuffleArray<T>(arrayIn: T[]): T[] {
const array = [...arrayIn];
for (let i = array.length - 1; i > 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
const temp = array[i];
if (temp === undefined || array[j] === undefined) {
throw new Error('Invalid shuffle index');
}
array[i] = array[j]; // eslint-disable-line no-param-reassign
array[j] = temp; // eslint-disable-line no-param-reassign
}
return array;
}
// https://stackoverflow.com/questions/14822153/escape-single-quote-in-xpath-with-nokogiri
// example str: "That's mine", he said.
function escapeXpathStr(str: string): string {
const parts = str.split("'").map((token: string) => `'${token}'`);