This file contains hidden or 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 Node { | |
| constructor(value) { | |
| this.value = value; | |
| this.next = null; | |
| this.prev = null; | |
| } | |
| } | |
| class DoublyLinkedList { | |
| constructor() { |
This file contains hidden or 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 TicTacToe { | |
| constructor() { | |
| this.board = Array(3) | |
| .fill(null) | |
| .map(() => Array(3).fill(null)); | |
| this.gameOver = false; | |
| this.winner = null; | |
| this.currentPlayer = "X"; | |
| this.winningPositions = [ | |
| [0, 1, 2], |
This file contains hidden or 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.prototype.myBind = function (scope, ...args) { | |
| scope.fn = this; | |
| return function () { | |
| return scope.fn(...args); | |
| }; | |
| }; | |
| Function.prototype.myApply = function (scope, args) { | |
| scope.fn = this; | |
| return scope.fn(...args); |
This file contains hidden or 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
| /* | |
| Author: Pawan Kumar | |
| Date : 04/28/2023 | |
| Location: Bangalore, India | |
| */ | |
| class MyPromise { | |
| constructor(executor) { | |
| let resolved = false; | |
| let rejected = false; |
This file contains hidden or 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 findRepeatingIndex(string) { | |
| const map = {}; | |
| for (let i = 0; i < string.length; i++) { | |
| const char = string[i]; | |
| if (!map[char]) { | |
| map[char] = { startingIndex: i }; | |
| } else { | |
| map[char].endIndex = i; | |
| } | |
| } |
This file contains hidden or 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 default class MyPromise { | |
| constructor(executor) { | |
| let resolved = false; | |
| let rejected = false; | |
| let resolveValue; | |
| let rejectValue; | |
| let resolveCallbacks = []; | |
| let rejectCallbacks = []; | |
| function resolve(value) { |
This file contains hidden or 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 Node { | |
| constructor(key, value) { | |
| this.key = key; | |
| this.value = value; | |
| } | |
| } | |
| class LinkedList { | |
| constructor() { | |
| this.head = null; |
This file contains hidden or 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 isPalindrome(str) { | |
| let low = 0; | |
| let high = str.length - 1; | |
| while (low < high) { | |
| if (str[low] !== str[high]) return false; | |
| low++; | |
| high--; | |
| } | |
| return true; | |
| } |
This file contains hidden or 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 TrieNode { | |
| constructor() { | |
| this.children = {}; | |
| this.end = false; | |
| } | |
| } | |
| class Trie { | |
| constructor() { | |
| this.root = new TrieNode(); |
This file contains hidden or 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 Graph { | |
| constructor() { | |
| this.adjList = new Map(); | |
| } | |
| addVertex = (v) => { | |
| if (!this.adjList.has(v)) { | |
| this.adjList.set(v, []); | |
| } | |
| }; |
OlderNewer