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* parseNdjson(ndjson) { | |
let i = 0; | |
do { | |
const newline = ndjson.indexOf("\n", i); | |
const string = newline === -1 ? ndjson.slice(i) : ndjson.slice(i, newline); | |
const json = string.trim(); | |
if (json) { | |
yield JSON.parse(json); | |
} | |
i = newline + 1; |
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
// guard against circular properties built in | |
function flatten(array) { | |
const { isArray } = Array; | |
if (!isArray(array)) { | |
return []; | |
} | |
const visited = new WeakSet; | |
const result = []; | |
const stack = [array]; |
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 map = { | |
"-1": "💥", | |
"0": "🟦", | |
}; | |
const inRange = (number, max) => 0 <= number && number < max; | |
const neighbors = [ | |
[-1, -1], [-1, 0], [-1, 1], | |
[0, -1], [ 0, 1], |
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 languageCache = new Map(); | |
let visitedNodes; | |
let language; | |
const resetVisitedNodes = () => { | |
visitedNodes = new WeakSet(); | |
}; | |
const formatRegex = /\{([^\}]*)\}/gui; |
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
Please read my first comment before drawing your own conclusion and take the points stated there into consideration as well | |
-------------------------------------------------------------------------------- | |
Object iteration test in node 12.2.0, v8 7.4.288.21-node.17 | |
Let O be object with properties x = 1, y = 1, z = 1, then iterate over the values and sum them, storing the result in variable `total` | |
-------------------------------------------------------------------------------- | |
O = { x: 1, y: 1, z: 1 } |
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
"use strict"; | |
const benchmark = require("benchmark"); | |
const suite = new benchmark.Suite; | |
/** SETUP BEGIN */ | |
const length = 100; | |
const value = ""; | |
const arrayOf = (function () { | |
function* generator(length, fill) { |
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 limits = [ | |
{ "x<": [90, 8] }, | |
{ "x<": [80, 7.9] }, | |
]; | |
const re = /^x?([<>]=?)$|^([<>]=?)x$/i; | |
const comparators = { | |
"<": (a, b) => a < b, | |
"<=": (a, b) => a <= b, | |
">": (a, b) => a > b, |
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
@SuppressWarnings("ForLoopReplaceableByForEach") | |
public final class Sum { | |
private Sum() {} | |
public static byte of(byte[] array) { | |
if (array == null) { | |
return 0; | |
} | |
byte result = 0; | |
for (int i = 0, length = array.length; i < length; ++i) { |
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 partialBinder = ((hole, rest) => { | |
"use strict"; | |
function partiallyBound(fn, args, ...missing) { | |
const argsLen = args.length; | |
const missingIter = missing[Symbol.iterator](); | |
for (let i = 0; i < argsLen; ++i) { | |
switch (args[i]) { | |
case hole: break; | |
case rest: args.splice(i, 1, ...missing); return fn.apply(this, args); | |
default: continue; |
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 csvEscape = function() { | |
const map = { | |
";": ",", | |
"\n": "\\n" | |
}; | |
const replacerRe = /./gsm; | |
const replacer = x => `\\x${x.charCodeAt(0).toString(16).padStart(2, 0)}`; | |
const escaped = Object.keys(map).map(x => x.replace(replacerRe, replacer)); | |
const escapeRe = new RegExp(escaped.join("|"), "g"); | |
const escape = x => map[x]; |