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 BNode { | |
| constructor (value) { | |
| this.data = value; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| search(values) { | |
| let c = values.indexOf(this.data) >=0 ? 1 : 0; |
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 BNode { | |
| constructor (value) { | |
| this.data = value; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| search(values) { | |
| let c = values.indexOf(this.data) >=0 ? 1 : 0; |
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
| // a + b * c + d | |
| // a b c * + d + | |
| // a + b * c + d | |
| // a b c * + d + | |
| function infixToPostfix(input) { |
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 stockSpan(array) { | |
| let answer = []; | |
| array.forEach((stock, index) => { | |
| let count = 1; | |
| for(let i = index - 1; (i >= 0) && (array[i] <= stock); i--) { | |
| count++; | |
| } |
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 arr1 = [1, 3, 5, 7, 11, 17, 21]; | |
| const arr2 = [-1, 0, 2, 3, 9, 11, 29]; | |
| function intersection(arr1, arr2) { | |
| let result = []; | |
| let p1 = 0, p2 = 0; | |
| while((p1 < arr1.length) && (p2 < arr2.length)) { | |
| if (arr1[p1] == arr2[p2]) { |
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 arr = [0, -1, 2, -3, 1]; | |
| // [ -3, -1, 0, 1, 2 ] | |
| function triplets(arr) { | |
| let sorted = arr.sort((a, b) => { return a > b; }); | |
| let answer = []; | |
| for(p1 = 0; p1 < sorted.length - 2; p1++) { |
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 arr = [-1, -1, 1, 1, 1, 1, 7, 11, 11]; | |
| // [ -1, 2, 1, 4, 7, 1, 11, 2]; | |
| class Stack { | |
| constructor() { | |
| this.values = []; | |
| } | |
| push(v) { |
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://www.geeksforgeeks.org/delete-consecutive-words-sequence/ | |
| function deleteConsecutive(arr) { | |
| let stack = new Stack(); | |
| arr.forEach(element => { | |
| if (element == stack.peek()) { | |
| stack.pop(); | |
| } else { | |
| stack.push(element); | |
| } |
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 basicCalc(str) { | |
| let result = 0, length = str.length, sign = 1, char; | |
| let stack = []; | |
| for (let i = 0; i < length; i++) { | |
| char = str.charAt(i); | |
| if (char >= '0') { | |
| //find all the chars | |
| let num = 0; |
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 indexOf(string, query) { | |
| for (let i = 0; i < string.length; i++) { | |
| //str.charAt(i) | |
| for (let q = 0; q < query.length; q++) { | |
| if (string[i+q] != query[q]) { | |
| break; | |
| } |