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
const flattenObject = (value, key = null, flattenedObject = {}) => { | |
if ( | |
['string', 'number', 'bigint', 'boolean', 'undefined', 'symbol'].includes(typeof value) || | |
value === null || | |
value instanceof Date | |
) { | |
flattenedObject[key] = value; | |
} else if (Array.isArray(value)) { | |
value.forEach((childValue, childIndex) => { | |
flattenObject(childValue, `${key}[${childIndex}]`, flattenedObject); |
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
const transformObjectToIdealTree = (node, { nodeIdPropName = 'name', nodeChildrenPropName = 'children' }) => { | |
const transform = (node) => { | |
const childNodes = Object.keys(node).map(child => ({ [nodeIdPropName]: child })); | |
for (const childNode of childNodes) { | |
childNode[nodeChildrenPropName] = transform(node[childNode[nodeIdPropName]]); | |
} | |
return childNodes; | |
}; | |
return transform(node); | |
}; |
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
const GRID_PARTS_VARIANT_LIGHT = 'LIGHT'; | |
const GRID_PARTS_VARIANT_DOUBLE = 'DOUBLE'; | |
const GRID_PART_VARIANTS_DICTIONARY = { | |
[GRID_PARTS_VARIANT_LIGHT]: '─│┌┐└┘├┤┬┴┼', | |
[GRID_PARTS_VARIANT_DOUBLE]: '═║╔╗╚╝╠╣╦╩╬' | |
}; | |
/** | |
* Create grid parts mapping object |
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
const usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; |
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
const allowedSortValueTypes = ['string', 'number', 'bigint']; | |
const usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const insertState = (value, list, acc, isInserted) => { | |
const [head, tail] = usePrologStyleList(list); |
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
const usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const listReverseState = (list, reversedList, acc) => { | |
const [head, tail] = usePrologStyleList(list); | |
if (head === undefined) { | |
return reversedList = acc; |
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
const usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const useErlangStyleString = (string, resultString) => { | |
const length = string.length; | |
if (!length) { | |
return resultString; | |
} |
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
const usePrologStyleList = (array) => { | |
const [head, ...tail] = array; | |
return [head, tail]; | |
}; | |
const listMinimumState = (list, minimum, acc) => { | |
const [head, tail] = usePrologStyleList(list); | |
if (head === undefined) { | |
return minimum = acc; |
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
const tuple = (...atoms) => Object.freeze( | |
atoms.reduce((partial, atom, index) => ({ | |
...partial, | |
['_' + ++index]: atom | |
}), {}) | |
); |
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
import {case_spec, match_spec} from './lib.mjs'; | |
const _case = (expression) => { | |
return { | |
of: (...predicates) => { | |
return case_spec(expression, () => predicates.reduce((partial, expr) => { | |
return { | |
...partial, | |
[match_spec(expression, expr.matchSpec)]: expr.matchFn | |
}; |
OlderNewer