View clojure.core.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 createGenerator(maybeIterable) { | |
const isGenerator = (maybeGenerator) => | |
"next" in maybeGenerator && | |
typeof maybeGenerator["next"] === "function" && | |
"throw" in maybeGenerator && | |
typeof maybeGenerator["throw"] === "function" && | |
"return" in maybeGenerator && | |
typeof maybeGenerator["return"] === "function"; | |
function* generatorFrom(maybeIterable) { |
View TicTacToe.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
import { useState } from "react"; | |
import "./styles.css"; | |
function createGrid(n = 3) { | |
return Array(n) | |
.fill(() => Array(n).fill(null)) | |
.map((createRow) => createRow()); | |
} |
View ShoppingCart.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
import { | |
useCallback, | |
useEffect, | |
useMemo, | |
useReducer, | |
useRef, | |
useState | |
} from "react"; | |
import { createPortal } from "react-dom"; |
View BinaryTree.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
class BinaryTreeNode { | |
constructor(value) { | |
this.left = null; | |
this.right = null; | |
this.values = [value]; | |
} | |
get value() { | |
const [firstValue] = this.values; |
View Queue.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
class QueueItem { | |
constructor(value) { | |
this.value = value; | |
this.head = null; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} |
View DoublyLinkedList.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
class DoublyLinkedListNode { | |
constructor(value) { | |
this.value = value; | |
this.head = null; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} |
View SinglyLinkedList.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
class SinglyLinkedListNode { | |
constructor(value) { | |
this.value = value; | |
this.tail = null; | |
} | |
valueOf() { | |
return this.value; | |
} | |
} |
View join.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
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] : '' |
View bring-your-own-form-library.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
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>) { |
View memoize-with-lru-cache.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 defaultCreateKey(args) { | |
return JSON.stringify(args); | |
} | |
class LruCache { | |
constructor(capacity = Infinity) { | |
this.capacity = capacity; | |
this.cache = new Map(); | |
} |
NewerOlder