View reverseArrayWithIterator.js
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
let a = [1, 2, 3, 4]; | |
for (let item of a) { | |
console.log(item); | |
} | |
function* reverse () { | |
for (let i = a.length - 1; i >= 0; i--) { | |
yield a[i]; | |
} |
View fetchJson.js
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
async function fetchJson(url, options, validate) { | |
const response = await fetch(url, options); | |
let json; | |
let jsonError; | |
try { | |
json = await response.json(); | |
} catch (error) { | |
jsonError = error; | |
} |
View aligned-table.js
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 alignedTable({ | |
alignments = [], | |
separator = ' ', | |
prefix = '', | |
suffix = '', | |
newLine = '\n', | |
rows = [], | |
} = {}) { | |
function toString() { | |
const lengths = {}; |
View smooth-expand.js
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 getElementsAfter(el, {stopAt, skip, only} = {}) { | |
let elements = []; | |
while (el) { | |
while (el.nextElementSibling) { | |
el = el.nextElementSibling | |
elements.push(el) | |
} | |
while (el && !el.nextElementSibling) { | |
el = el.parentElement |
View rubberBandEffect.ts
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 rubberBandEffect( | |
val: number, | |
lowerBounds: number, | |
upperBounds: number, | |
padding: number = 25, | |
): number { | |
const lowerLimit = lowerBounds - padding; | |
const upperLimit = upperBounds + padding; | |
if (val < lowerLimit) { |
View nodeColors.js
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 util = require('util'); | |
const colorize = (str, colorCodes) => `\x1b[${colorCodes[0]}m${str}\x1b[${colorCodes[1]}m`; | |
const bold = str => colorize(str, util.inspect.colors.bold); | |
const italic = str => colorize(str, util.inspect.colors.italic); | |
const underline = str => colorize(str, util.inspect.colors.underline); | |
const inverse = str => colorize(str, util.inspect.colors.inverse); | |
const white = str => colorize(str, util.inspect.colors.white); | |
const grey = str => colorize(str, util.inspect.colors.grey); |