Skip to content

Instantly share code, notes, and snippets.

View hk-skit's full-sized avatar
👨‍💻
On deep learning mode.

Hitesh Kumar hk-skit

👨‍💻
On deep learning mode.
View GitHub Profile
{
"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;",
// 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)) {
@hk-skit
hk-skit / spiral_matrix.js
Created May 24, 2021 11:10
Print matrix in spiral order
const Direction = {
L_R: 0,
T_B: 1,
R_L: 2,
B_T: 3,
};
const spiral = (matrix) => {
if (matrix.length === 0) {
return;
export class BinaryTreeNode {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
/**
* Inserts node in level order.
*
import { BinaryTreeNode } from './BinaryTreeNode';
export class BinaryTree {
constructor() {
this.root = null;
}
get isEmpty() {
return this.root === null;
}
@hk-skit
hk-skit / Stack.js
Last active January 27, 2019 11:27
class Stack {
constructor() {
this.list = new LinkedList();
}
get isEmpty() {
return this.list.isEmpty;
}
/**
// Generator function.
*[Symbol.iterator]() {
let current = this.head;
while (current !== null) {
const { value } = current;
current = current.next;
yield value;
}
}
/**
* Iterator function.
*
* @returns
* @memberof LinkedList
*/
[Symbol.iterator]() {
let current = this.head;
const iterable = {
next: () => {
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class LinkedList {
constructor() {
class RangeGenerator {
constructor({
start = 0,
end = 1000,
step = 1
}) {
this.start = start;
this.end = end;
this.step = step;