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 * count() { | |
const maximum = | |
(arguments.length === 1 && typeof arguments[0] === "number") ? arguments[0] : | |
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("maximum")) ? arguments[0].maximum : | |
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("max")) ? arguments[0].max : | |
(arguments.length === 2 || arguments.length === 3) ? arguments[1] : 0; | |
const minimum = | |
(arguments.length === 1 && typeof arguments[0] === "number") ? 0 : | |
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("minimum")) ? arguments[0].minimum : |
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
// @flow | |
function _createReducer<T, K>(handler: { [$PropertyType<K, 'type'>]: ({ action, state }: { action: K, state: T }) => T }): (state: T, action: K) => T { | |
if (handler.hasOwnProperty(action.type)) | |
return handler[action.type]({ | |
action, | |
state | |
}); | |
return state; | |
} |
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
interface Matrix { | |
readonly [index: number]: { | |
readonly [index: number]: number; | |
}; | |
} | |
interface CartesianPoint { | |
x: number; | |
y: number; | |
z: number; | |
} |
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 formula_xfyz (x: string | symbol, y: string | symbol, z: string | symbol, f: '+' | '-' | '*' | '/' | '^') { | |
// function fn (it: { [x]: number, [y]: number }): { [z]: number}; | |
// function fn (it: { [x]: number, [z]: number }): { [y]: number}; | |
// function fn (it: { [y]: number, [z]: number }): { [x]: number}; | |
function fn (it: any): any { | |
const g = ({ | |
'+': [ (x: number, y: number): number /* z */ => x + y, | |
(x: number, z: number): number /* y */ => z - x, | |
(y: number, z: number): number /* x */ => z - y ], | |
'-': [ (x: number, y: number): number /* z */ => x - y, |
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 format_large_number (it) { | |
it = it.toString() | |
while ((/(?<=\d)(\d{3})($|(?=[,\.]))/gim).test(it)) { | |
it = it.replace(/(?<=\d)(\d{3})($|(?=[,\.]))/gim, ',$1') | |
} | |
return it; | |
} | |
function * dd3 (a, b, ax, bx, ay, by, n) { | |
if (ax === null || ax === undefined) ax = 0; |
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 { performance } = require('perf_hooks') | |
function generateLookupTables (...functions) { | |
const lookupTables = new Map() | |
for (const f of functions) | |
lookupTables.set(f, new Uint8Array(2 ** 8)) | |
for (let input = 0; input < 2 ** 8; input++) { | |
const bit_0 = (input >> 0) & 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 * getMove (...moves) { | |
if (moves.length === 9) yield moves | |
if (moves.length < 9) | |
for (let x = 0, X = 9; x < X; x++) | |
if (moves.length < 9 && !moves.includes(x)) | |
yield* getMove(...moves, x) | |
} |
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 * reorder (current, bucket) { | |
if (bucket.length === 0) yield current; | |
else if (bucket.length === 1) yield current.concat(bucket) | |
else if (bucket.length > 1) | |
for (let i = 0; i < bucket.length; i++) { | |
yield* reorder([...current, bucket[i]], [...bucket.slice(0, i), ...bucket.slice(i + 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
const pickByName = (obj, prop) => obj[prop]; | |
const pickAndTransformValue = (obj, [prop, transformer]) => | |
transformer(obj[prop]); | |
const addProps = (obj, [prop, secondProp]) => obj[prop] + obj[secondProp]; | |
const $pickByName = object => property => object[property] | |
const $pickAndTransformValue = object => ([property, transformer]) => transformer(object[property]) | |
const $addProps = object => ([prop, secondProp]) => object[prop] + object[secondProp]; |
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 replaceSelection(newString, oldString, stringIndex, stringLength) { | |
return oldString.substring(0, stringIndex) + newString + oldString.substring(stringIndex + stringLength) | |
} | |
function compile2({ source, sourceMap }, transform) { | |
const generatedMap = new Map() | |
let offset = 0 | |
let currentRelativePosition = 0 | |
let generated = `${source}` |