feat: ohhhhhh babe

This commit is contained in:
mpaulson 2022-07-26 21:33:34 -06:00
parent 37aa7f0066
commit b35341ac1a
7 changed files with 31 additions and 13 deletions

View file

@ -17,9 +17,8 @@ module.exports = {
"CompareBinaryTrees", "CompareBinaryTrees",
"DFSOnBST", "DFSOnBST",
"Trie", "Trie",
"DFSGraphList", "DFSGraphMatrix",
"BFSGraphList", "BFSGraphList",
"BFSGraphMatrix",
"Map", "Map",
], ],
} }

View file

@ -251,14 +251,14 @@ module.exports = {
BTBFS: { BTBFS: {
type: "fn", type: "fn",
fn: "bfs", fn: "bfs",
args: "head: BinaryNode<number>", args: "head: BinaryNode<number>, needle: number",
return: "number[]", return: "boolean",
}, },
CompareBinaryTrees: { CompareBinaryTrees: {
type: "fn", type: "fn",
fn: "compare", fn: "compare",
args: "a: BinaryNode<number>, b: BinaryNode<number>", args: "a: BinaryNode<number> | null, b: BinaryNode<number> | null",
return: "boolean", return: "boolean",
}, },

View file

@ -7,11 +7,11 @@ test("post order", function () {
5, 5,
15, 15,
10, 10,
15,
29, 29,
45, 45,
30, 30,
100, 100,
50,
20, 20,
]); ]);
}); });

View file

@ -1,7 +1,7 @@
import compare from "@code/CompareBinaryTrees"; import compare from "@code/CompareBinaryTrees";
import { tree, tree2 } from "./tree"; import { tree, tree2 } from "./tree";
test("bt bfs", function () { test("Compare Binary Trees", function () {
expect(compare(tree, tree)).toEqual(true); expect(compare(tree, tree)).toEqual(true);
expect(compare(tree, tree2)).toEqual(false); expect(compare(tree, tree2)).toEqual(false);
}); });

View file

@ -1,16 +1,33 @@
export function test_list(list: List<number>): void { export function test_list(list: List<number>): void {
list.add(5); list.append(5);
list.add(7); list.append(7);
list.add(9); list.append(9);
// @ts-ignore
console.log(list.data);
expect(list.get(2)).toEqual(9); expect(list.get(2)).toEqual(9);
expect(list.removeAt(1)).toEqual(7); expect(list.removeAt(1)).toEqual(7);
// @ts-ignore
console.log(list.data);
expect(list.length).toEqual(2); expect(list.length).toEqual(2);
list.add(11); list.append(11);
// @ts-ignore
console.log(list.data);
expect(list.removeAt(1)).toEqual(9); expect(list.removeAt(1)).toEqual(9);
expect(list.remove(9)).toEqual(undefined); expect(list.remove(9)).toEqual(undefined);
expect(list.removeAt(0)).toEqual(5); expect(list.removeAt(0)).toEqual(5);
expect(list.removeAt(0)).toEqual(11); expect(list.removeAt(0)).toEqual(11);
expect(list.length).toEqual(0); expect(list.length).toEqual(0);
list.prepend(5);
list.prepend(7);
list.prepend(9);
expect(list.get(2)).toEqual(5);
expect(list.get(0)).toEqual(9);
expect(list.remove(9)).toEqual(9);
expect(list.length).toEqual(2);
expect(list.get(0)).toEqual(7);
} }

View file

@ -77,7 +77,7 @@ list2[6] = [
// >(2) --> (3) <----(6) // >(2) --> (3) <----(6)
export const matrix2: WeightedAdjacencyMatrix = [ export const matrix2: WeightedAdjacencyMatrix = [
[0, 3, 1, 0, 0, 0, 0], // 0 [0, 3, 1, 0, 0, 0, 0], // 0
[0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0],
[0, 0, 7, 0, 0, 0, 0], [0, 0, 7, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 5, 0, 2, 0], [0, 1, 0, 5, 0, 2, 0],

4
src/global.d.ts vendored
View file

@ -8,7 +8,9 @@ declare interface List<T> {
removeAt(index: number): T | undefined; removeAt(index: number): T | undefined;
remove(item: T): T | undefined; remove(item: T): T | undefined;
get(index: number): T | undefined; get(index: number): T | undefined;
add(item: T): void; prepend(item: T): void;
append(item: T): void;
insertAt(item: T, idx: number): void;
} }
declare type CompleteGraphEdge = { from: number; to: number; weight: number }; declare type CompleteGraphEdge = { from: number; to: number; weight: number };