# Give executable permission to script;
chmod +x update.sh;
# Execute with mode major;
./update.sh major;
# Execute with mode minor;
./update.sh minor;
# Execute with mode patch;
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
| const assert = require('assert'); | |
| function hasSingleCycle(array) { | |
| let numberOfVisitedNodes = 0; | |
| let currentIndex = 0; | |
| while (numberOfVisitedNodes < array.length) { | |
| // If we go back to the first element, | |
| // That shows, we have an infinite loop before our loop ends. | |
| if (currentIndex === 0 && numberOfVisitedNodes > 0) return false; | |
| currentIndex = jump(currentIndex, array); |
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
| const assert = require("assert"); | |
| class Node { | |
| constructor(name) { | |
| this.name = name; | |
| this.children = []; | |
| } | |
| addChild(name) { | |
| this.children.push(new Node(name)); |
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 mergeLinkedLists(headOne, headTwo) { | |
| let p1 = headOne; | |
| let p1Prev = null; | |
| let p2 = headTwo; | |
| while (p1 !== null && p2 !== null) { | |
| // If our second linkedlist's pointer value is bigger | |
| if (p1.value < p2.value) { | |
| // Store the previous | |
| p1Prev = p1; | |
| // Move the pointer to next item. |
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
| const assert = require("assert"); | |
| // Leetcode: https://leetcode.com/problems/word-ladder/ | |
| // Leetcode: https://leetcode.com/problems/word-ladder-ii/ | |
| // Inputs: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] | |
| // Output: 5 | |
| /* | |
| A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: |
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
| // https://leetcode.com/problems/maximum-value-after-insertion | |
| const assert = require("assert"); | |
| // n very large string represent integer, | |
| // x [1-9] | |
| // return string | |
| function maxValue(n, x) { | |
| // If the input is empty. | |
| if (!n || n.length === 0) { | |
| return 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
| class BST { | |
| constructor(value) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| } | |
| function validateBst(tree) { | |
| return validate(tree, -Infinity, Infinity) |
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 BST { | |
| constructor(value) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| insert(value) { | |
| let currentNode = this; | |
| while (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
| const assert = require('assert'); | |
| // '(', '{', '[' are called "openers." | |
| // ')', '}', ']' are called "closers." | |
| function validateBrackets(input) { | |
| const brackets = { | |
| openings: { | |
| '{': '}', | |
| '(': ')', |
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 sum(a) { | |
| return function (b) { | |
| if (b !== undefined) { | |
| return sum(a + b) | |
| } | |
| return a; | |
| } | |
| } |