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 { uniqueBy } from "remeda"; | |
import { SuperMap } from "./SuperMap.ts"; | |
export class Graph<T> { | |
adjacencyList: SuperMap<T, T[]>; | |
private serialize: (input: T) => string; | |
private deserialize: (input: string) => T; | |
private printVal: (input: T) => any; | |
constructor( |
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 { piped } from "remeda"; | |
import z from "zod"; | |
const getBlocks = piped( | |
(a: string) => a.split(""), | |
(a) => | |
a.map((char, index) => { | |
const isEven = index % 2 === 0; | |
const charValue = z.number().parse(+char); |
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 { buildMatrix } from "./build-matrix"; | |
describe("Build Matrix", () => { | |
it("Should turn my shit into matrix of rows", () => { | |
expect( | |
buildMatrix({ | |
// prettier-ignore | |
elements: [ | |
1/1, | |
1/3, 2/3, |
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 reduce<T, U>( | |
arr: T[], | |
reducer: (acc: U, currentValue: T, index: number, array: T[]) => U, | |
initialValue: U, | |
index: number = 0 | |
): U { | |
// Base case: if the index is out of bounds, return the accumulated value | |
if (index >= arr.length) { | |
return initialValue; | |
} |
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 at = <T,>(arr: T[], index: number) => index < 0 | |
? arr[arr.length + index] | |
: arr[index]; | |
let recursiveFibCount = 0 | |
const rFibonnaci = (num = 1, prevSeq: number[] = [0]): number => { | |
if(prevSeq.length === num) { | |
return at(prevSeq, -1) | |
} | |
if(prevSeq.length === 1) return rFibonnaci(num, [0, 1]) |
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 moveAllInstancesToEnd<T extends any[] | string>( | |
input: T, | |
shouldMoveCb: (input: T[number]) => unknown | |
): T { | |
if(Array.isArray(input)){ | |
let notMoved: any = [] | |
let moved: any = [] | |
for(let el of input){ | |
if(shouldMoveCb(el)){ | |
moved.push(el) |
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 getCounts = <T,>( | |
input: Iterable<T>, | |
shouldCountCb: (input: T) => unknown, | |
serializeKey: (input: T) => any = input => input, | |
) => { | |
let counts = {} as Record<any, number> | |
for(let val of input){ | |
if(shouldCountCb(val)){ | |
counts[serializeKey(val)] = (counts[serializeKey(val)] ?? 0) + 1 | |
} |
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
export const Accordion = ( | |
{ | |
children, | |
show | |
} : { | |
children: ReactNode, | |
show: boolean | |
} | |
) => { | |
return show ? |
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 result = <T,E extends Error>(cb: () => T): [null, E] | [T, null] => { | |
try { | |
return [cb(), null] | |
} catch(e){ | |
return [null,e as E] | |
} | |
} | |
const failsSometimes = () => { | |
if(Math.random() > .5){ | |
throw new Error("Failed") |
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 SyncPromise<T> { | |
private value?: T; | |
private error?: any; | |
private isFulfilled: boolean = false; | |
private isRejected: boolean = false; | |
constructor(executor: () => T) { | |
try { | |
this.resolve(executor()); | |
} catch (e) { |
NewerOlder