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
const buttons = [...document.getElementsByClassName('button')]; | |
let focusedButtonIndex = 0; | |
buttons[focusedButtonIndex].focus(); | |
window.addEventListener('keydown', event => { | |
if ( buttons.some(button => button === event.target) ) { | |
if ( event.code === 'ArrowDown' || event.code === 'ArrowUp' ) { | |
buttons[focusedButtonIndex ^= 1].focus(); | |
} |
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
/** | |
* Implement Circular/Ring Buffer basic behaviour. | |
* | |
* @version 1 | |
* | |
* @example | |
* const buffer = new CircularBuffer(3); | |
* | |
* buffer.list(); // [] | |
* buffer.push('URL 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
/** | |
* Basic password generator. | |
* Alphabet: digits, English letters in both cases, and special characters. | |
* | |
* @param {number[]} range - list of two numeric values "from" and "to" which are UTF code points | |
* @param {number} length - password length, small values aren't recommended for security reasons | |
* | |
* @return {Generator<string, void, *>} | |
*/ | |
function* generatePassword ( range = [33, 126], length = 20 ) { |
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
/** @see {@link https://en.wikipedia.org/wiki/Digit_sum} */ | |
const dsum = n => n < 10 ? n : n % 10 + dsum(n / 10 | 0); | |
/** @see {@link https://encyclopediaofmath.org/wiki/Factorial} */ | |
const fact = n => n ? n * fact(n - 1) : 1; | |
/** @see {@link https://encyclopediaofmath.org/wiki/Greatest_common_divisor} */ | |
const gcd = (a, b) => b ? gcd(b, a % b) : a; | |
/** @see {@link https://encyclopediaofmath.org/wiki/Power|Fast algorithm} */ |
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
/* Aim: | |
"function <function name>() { | |
[native code] | |
}" | |
*/ | |
function protect ( fn ) { | |
fn.toString = fn.toLocaleString = fn.toSource = function () { | |
return 'function ' + fn.name + '() { [native code] }'; | |
}; |
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
// basic implementation | |
function protect ( fn ) { | |
fn.toString = fn.toLocaleString = fn.toSource = function () { | |
return 'function ' + fn.name + '() { [native code] }'; | |
}; | |
} | |
// but indirect call still available, so fix it | |
var protect = (function () { | |
// function can be reassign with different name, so use functions itself instead of string names |