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
// Remove Duplicates from an array | |
const removeDuplicates = | |
arr => arr.filter((item, index) => index === arr.indexOf(item)); | |
const removeDuplicates1 = array => [...new Set(array)]; | |
const removeDuplicates2 = array => Array.from(new Set(array)); | |
// Flattens an array(doesn't flatten deeply). |
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
{ | |
"React Function Component Typescript": { | |
"prefix": "rfct", | |
"body": [ | |
"import type { FC } from \"react\"", | |
"import type { ${TM_FILENAME_BASE}Props } from \"./${TM_FILENAME_BASE}.types\"", | |
"", | |
"const ${TM_FILENAME_BASE}: FC<${TM_FILENAME_BASE}Props> = () => <div />;", | |
"", | |
"export default $TM_FILENAME_BASE;", |
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
// Given a string and a set of delimiters, reverse the words in the string while maintaining | |
// the relative order of the delimiters. For example, given "hello/world:here", return "here/world:hello". | |
// Follow-up: Does your solution work for the following cases: "hello/world:here/", "hello//world:here" | |
const reverseWords = (string, delimiters) => { | |
const aux = []; | |
let word = ''; | |
// O(n) | |
for (const str of string) { | |
if (!delimiters.has(str)) { |
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 Direction = { | |
L_R: 0, | |
T_B: 1, | |
R_L: 2, | |
B_T: 3, | |
}; | |
const spiral = (matrix) => { | |
if (matrix.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
interface StackConstructor<T> { | |
new <T>(n: number): Stack<T> | |
} | |
export class Stack<T>{ | |
private data: T[] = []; | |
static readonly OVERFLOW = 'OVERFLOW'; | |
static readonly UNDERFLOW = 'UNDERFLOW'; | |
constructor(private size: number) { | |
} | |
push(item: T): number | string { |
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 class BinaryTreeNode { | |
constructor(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
/** | |
* Inserts node in level order. | |
* |
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 { BinaryTreeNode } from './BinaryTreeNode'; | |
export class BinaryTree { | |
constructor() { | |
this.root = null; | |
} | |
get isEmpty() { | |
return this.root === null; | |
} |
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 Stack { | |
constructor() { | |
this.list = new LinkedList(); | |
} | |
get isEmpty() { | |
return this.list.isEmpty; | |
} | |
/** |
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
// Generator function. | |
*[Symbol.iterator]() { | |
let current = this.head; | |
while (current !== null) { | |
const { value } = current; | |
current = current.next; | |
yield 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
/** | |
* Iterator function. | |
* | |
* @returns | |
* @memberof LinkedList | |
*/ | |
[Symbol.iterator]() { | |
let current = this.head; | |
const iterable = { | |
next: () => { |
NewerOlder