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 tokens = [ | |
[/^\s+/, null], | |
[/^\[/, '['], | |
[/^]/, ']'], | |
[/^\{/, '{'], | |
[/^}/, '}'], | |
[/^:/, ':'], | |
[/^,/, ','], | |
[/^"/, '"'], | |
[/^\d+/, '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
// | |
// ----- Sequences ------------------------- | |
// | |
const range = (l, u = Infinity) => function* () { | |
while (true) { | |
if (l < u) { | |
yield l++; | |
continue; | |
} |
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
// | |
// ------- General utilities --- | |
// | |
type ArrayFromNumber<N extends number, A extends any[] = []> = A['length'] extends N ? A : ArrayFromNumber<N, [...A, any]>; | |
type Increment<T extends number> = [...ArrayFromNumber<T>, any]['length']; | |
type Decrement<T extends number> = ArrayFromNumber<T> extends [...(infer U), any] ? U['length'] : never; | |
type Rewind<Arr extends any[], I extends number, Depth extends number = 0> = Arr[I] extends '[' | |
? Depth extends 0 ? I : Rewind<Arr, Decrement<I>, Decrement<Depth>> |
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
// Utility types | |
type Length<T extends any[]> = T extends { length: infer L } ? L : never; | |
type BuildTuple<L extends number, T extends any[] = []> = | |
T extends { length: L } | |
? T | |
: BuildTuple<L, [...T, any]>; | |
type MultiAdd<N extends number, A extends number, I extends number> = | |
I extends 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 db = [ | |
{ | |
name: 'John Doe', | |
age: 28, | |
lastModified: Date.now(), | |
lastAccessed: Date.now() | |
}, | |
{ | |
name: 'Jane Smith', | |
age: 30, |
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
// Create "backend" object to hold data for getters and setters on main object | |
const _ = Object.create( null ); | |
Object.defineProperties( | |
_, | |
{ | |
firstname: { | |
value: 'John', | |
writable: true, | |
enumerable: false, |
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 invoices = [ | |
{ invoiceId: "c1-5b", vendor: "GE", paid: true }, | |
{ invoiceId: "a", vendor: "GE", paid: false }, | |
{ invoiceId: "-7c", vendor: "Whirlpool", paid: true }, | |
{ invoiceId: "b", vendor: "Bosch", paid: true }, | |
{ invoiceId: "9b54-dbdd", vendor: "Bosch", paid: false }, | |
{ invoiceId: "2cac788-", vendor: "Whirlpool", paid: true }, | |
{ invoiceId: "99cd9c14", vendor: "Bosch", paid: false }, | |
{ invoiceId: "a1854b-14b", vendor: "Frigidaire", paid: false }, | |
{ invoiceId: "43b76a75", vendor: "Bosch", paid: true }, |
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 invoices = [ | |
{invoiceId: "c1-5b", vendor: "GE", paid: true}, | |
{invoiceId: "a", vendor: "GE", paid: false}, | |
{invoiceId: "-7c", vendor: "Whirlpool", paid: true}, | |
{invoiceId: "b", vendor: "Bosch", paid: true}, | |
{invoiceId: "9b54-dbdd", vendor: "Bosch", paid: false}, | |
{invoiceId: "2cac788-", vendor: "Whirlpool", paid: true}, | |
{invoiceId: "99cd9c14", vendor: "Bosch", paid: false}, | |
{invoiceId: "a1854b-14b", vendor: "Frigidaire", paid: false}, | |
{invoiceId: "43b76a75", vendor: "Bosch", paid: true}, |
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
class JQ { | |
constructor(list) { | |
let i = 0; | |
while (list[i] !== undefined) { | |
this[i] = list[i]; | |
i++; | |
} | |
this.length = i; | |
} |
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
class JQ { | |
constructor(list) { | |
let i = 0; | |
while (list[i] !== undefined) { | |
this[i] = list[i]; | |
i++; | |
} | |
this.length = i; |
NewerOlder