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 path = require("path"); | |
const findUp = require("find-up"); | |
const globby = require("globby"); | |
const getLernaRoot = () => findUp.sync("lerna.json"); | |
const getPackageJsonRoot = () => findUp.sync("package.json"); | |
const toPackageJsonPath = originalPath => |
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 { readFileSync, writeFileSync } = require('fs'); | |
const writeNamedExportsToPathOfPkg = (output, path, namedExports) => { | |
if (!namedExports || namedExports.length === 0) { | |
return; | |
} | |
const pkgJson = JSON.parse(readFileSync(output, 'utf8')); | |
let level = pkgJson; |
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
#!/usr/bin/env node | |
function window(values = [], step = 1, size = 1) { | |
function* _window() { | |
for (let i = 0; i < values.length; i += step) { | |
const items = values.slice(i, i + size); | |
yield items; | |
} | |
} |
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
type GetValueFn<TIdentity, TValue> = (id: TIdentity) => Promise<TValue>; | |
type KeyValueObject<TValue> = { [key: string]: TValue }; | |
const getObject = <TIdentity, TValue>( | |
getValue: GetValueFn<TIdentity, TValue> | |
) => async (itemIds: Array<TIdentity>): Promise<KeyValueObject<TValue>> => { | |
return Object.fromEntries( | |
await Promise.all( | |
itemIds.map(async itemId => [itemId, await getValue(itemId)]) | |
) |
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 floodFill = (grid = [], startPoint, newColor) => { | |
const [y, x] = startPoint; | |
const startColor = grid[y][x]; | |
const points = [startPoint]; | |
while (points.length) { | |
const [y, x] = points.shift(); | |
grid[y][x] = null; |
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 takeNumber = pattern => { | |
const [_number] = pattern.match(/^\d+/g) || []; | |
return parseInt(_number, 10) || 1; | |
}; | |
const str = pattern => { | |
let count = 1; | |
let parts = ""; | |
let part = ""; |
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 permute(arr) { | |
if (arr.length === 2) { | |
const [a, b] = arr; | |
return [[a, b], [b, a]]; | |
} | |
let permutationItems = []; | |
for (let idx = 0; idx < arr.length; idx++) { | |
const first = arr[idx]; |
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
#!/usr/bin/env node | |
const matrix = [ | |
[1, 1, 1, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0], | |
[1, 1, 1, 1, 0, 0], | |
[1, 1, 1, 0, 0, 0], | |
[1, 1, 1, 1, 1, 0], | |
[1, 1, 1, 0, 0, 0] | |
]; |
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
#!/usr/bin/env node | |
const NUMBERS = { | |
0: "zero", | |
1: "one", | |
2: "two", | |
3: "three", | |
4: "four", | |
5: "five", | |
6: "six", |
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
#!/usr/bin/env node | |
// This horrible design is the implementation of an interview question. | |
class Subscription { | |
constructor(parent, eventName, callback) { | |
this.parent = parent; | |
this.eventName = eventName; | |
this.callback = callback; | |
} |