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
/** | |
* group an array by accessor | |
* @param arr array of elements | |
* @param accessor called on element, must return a value from the elements after which they are to be grouped | |
* @returns Map where keys are defined by accessor function and values are an array of elements | |
*/ | |
const groupBy = (a, accessor) => { | |
if (!Array.isArray(a)) throw 'param a is not an array'; | |
if (typeof(accessor) != 'function') throw 'param accessor is not a function'; | |
return a.reduce( |
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 sqm(base, exponent, mod) { | |
let ze = 1; let a = base; | |
while (exponent) { | |
if (exponent & 1) ze = (ze * a) % mod; | |
a = (a * a) % mod; | |
exponent = exponent >> 1; | |
// console.log("Ze: " + ze + " A: " + a); | |
} | |
return ze; | |
} |