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
class BinaryTreeNode { | |
constructor(value) { | |
this.left = null; | |
this.right = null; | |
this.values = [value]; | |
} | |
get value() { | |
const [firstValue] = this.values; |
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
class QueueItem { | |
constructor(value) { | |
this.value = value; | |
this.head = null; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} |
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
class DoublyLinkedListNode { | |
constructor(value) { | |
this.value = value; | |
this.head = null; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} |
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
class SinglyLinkedListNode { | |
constructor(value) { | |
this.value = value; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} | |
} |
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 GetTail<Items extends string[]> = Items extends [any, ...infer Tail] | |
? Tail | |
: string[]; | |
type HasTail<Items extends string[]> = Items extends [any, any, ...any[]] | |
? true | |
: false; | |
type Join<Strs extends string[], Delimiter extends string = ""> = HasTail<Strs> extends false | |
? Strs[0] extends string ? Strs[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
import "./styles.css"; | |
import type { FormEvent } from "react"; | |
function getFormValues(formElement: HTMLFormElement) { | |
return Object.fromEntries(new FormData(formElement).entries()); | |
} | |
function Form({ validator = {}, handleSubmit, children }) { | |
function handleBlurs(e: FormEvent<HTMLFormElement>) { |
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 defaultCreateKey(args) { | |
return JSON.stringify(args); | |
} | |
class LruCache { | |
constructor(capacity = Infinity) { | |
this.capacity = capacity; | |
this.cache = new Map(); | |
} |
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 DeepFlatten<T> = T extends Array<infer Item> ? DeepFlatten<Item> : T; | |
function deepFlatten<T extends any[]>(arr: T): DeepFlatten<T>[] { | |
function recurseUntilFlat<U extends any[]>(arr: U): U { | |
return arr.reduce((acc, v) => { | |
return [...acc, ...Array.isArray(v) ? recurseUntilFlat(v) : [v]] | |
}, []); | |
} | |
return recurseUntilFlat(arr); |
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 createMultiMap(items, { getKeys } = {}) { | |
if (typeof getKeys !== "function") { | |
throw new Error( | |
"The `getKeys` function passed into `createMultiMap` must be a function." | |
); | |
} | |
function set(m, keys, value) { | |
if (keys.length === 0) { | |
return; |
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
// A JavaScript `Date` is fundamentally specified as the number of milliseconds that have elapsed since the ECMAScript epoch, | |
// which is defined as January 1, 1970, UTC (equivalent to the UNIX epoch). | |
// | |
// However, depending on how you construct a `Date` the date passed in can be parsed as a date in your local time zone or a UTC date. | |
// For instance `"2022-08-01"` will be treated as a UTC value, but `"2022-08-01T00:00:00.000"` will be treated as if it | |
// is a localised date and offset before setting the underlying value of the `Date`. Similarly, there is a difference | |
// between passing in `(2022, 7, 1, 0, 0, 0, 0)` which is assumed to be localised and `Date.UTC(2022, 7, 1, 0, 0, 0, 0)` | |
// which is a unix timestamp (in milliseconds). | |
// Firstly, let's print our local timezone and the current timezone offset: |