• Oct 15, 2022 •CodeCatch
0 likes • 92 views
class DFS { public dfs(G: DFSGraph, startVert: number) { let visited: boolean[] = Array<boolean>(); // Pre-populate array: for(let i = 0; i < G.size; i++) { visited.push(false); } let s: number[] = new Array(); visited[startVert] = true; s.push(startVert); while(s.length > 0) { const v = s.pop(); for(let adjV of G.adj[v]) { if(!visited[adjV]) { visited[adjV] = true; s.push(adjV); } } } } public dfsRecursive(G: DFSGraph, startVert: number) { let visited: boolean[] = Array<boolean>(); // Pre-populate array: for(let i = 0; i < G.size; i++) { visited.push(false); } this.dfsAux(G, startVert, visited); } private dfsAux(G: DFSGraph, v: number, visited: boolean[]) { visited[v] = true; for(let adjV of G.adj[v]) { if(!visited[adjV]) { // this.foo(); // Something can happen before the visit. this.dfsAux(G, adjV, visited); // this.bar(); // Something can happen after the visit. } } } }
• Oct 22, 2024 •C S
0 likes • 2 views
function removeElement(nums: number[], val: number): number { let zeroStartIndex = 0; for(let i = 0; i < nums.length; i++) { if(nums[i] !== val) { nums[zeroStartIndex] = nums[i]; zeroStartIndex++; } } return zeroStartIndex; };
• May 11, 2025 •C S
0 likes • 6 views
https://ui.shadcn.com/create?base=base&template=vite&baseColor=stone&theme=blue&item=pagination-example
• Oct 23, 2025 •opovolotskyi-7e4a
0 likes • 9 views
let state let prevValue function customState(initialValue){ if(state===undefined) { state=initialValue } function setState (newValue){ if(typeof newValue ==="function") { } state=newValue render() } return [state,setState] +(1) setState(2) setState((prev, next) => { return cancelIdleCallback() }) // state
0 likes • 3 views
function removeDuplicates(nums: number[]): number { nums.splice(0, nums.length, ...Array.from(new Set(nums))); return nums.length; }; console.log(removeDuplicates([1, 2, 3, 4, 5, 6]))
• Nov 21, 2023 •AustinLeath
0 likes • 25 views
// Print Hello, World! console.log("Hello, World!");