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
// Example args | |
const filters = ['LOWER_LETTERS', 'NUMS']; | |
const pwLength = 5; | |
// ****************************************** | |
/** | |
* @param {number} pwLength | |
* @param {string []} filters | |
* @return {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
// Example args | |
const filters = ['LOWER_LETTERS', 'NUMS']; | |
const pwLength = 5; | |
// ****************************************** | |
/** | |
* @param {number} pwLength | |
* @param {string []} filters | |
* @return {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
const delete = (value, root) => { | |
switch (true) { | |
// value doesn't exist in BST | |
case root === null: | |
return null; | |
// if value exists, it must be in right sub-tree | |
case value > root.value: | |
root.right = this.delete(value, root.right); | |
return root; |
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
/** | |
* @param {nums []} | |
* @param {targetSum Int} | |
* @return {combination [int, int]} | |
*/ | |
const findCombination = (nums, targetSum) => { | |
let numsCache = new Set(); | |
for (let i = 0; i < nums.length; i++) { |
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 hasNeedle = (needle) => (currVal) => needle === currVal; | |
const isInHaystack = (needle, haystack) => haystack.some(hasNeedle(needle)); | |
const needle = 'Foo'; | |
const haystack = ["Bar", "Foo Bar", "Bar Foo", "Foo Foo"] | |
isInHaystack(needle, haystack); |
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 randomTypo = (msg) => { | |
const NUM_OF_MESSAGES = 100; | |
const NUM_OF_TYPOS = 10; | |
const LETTER_CHAR_CODE_START = 65; | |
const LETTER_CHAR_CODE_END = 122; | |
const typoIndices = new Set(); | |
while (typoIndices.size < NUM_OF_TYPOS) { | |
const randIdx = randBetween(0, NUM_OF_MESSAGES - 1); | |
typoIndices.add(randIdx); |
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 readline = require('readline'); | |
console.log('Welcome to Guessing Game!'); | |
const Terminal = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
const App = { |
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 flip = (node) => { | |
const queue = [node]; | |
while (queue.length) { | |
const currNode = queue.shift(); | |
// swap | |
[currNode.left, currNode.right] = [currNode.right, currNode.left]; | |
currNode.left && queue.push(currNode.left); |
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 isValid = (address) => address >= 0 && address <= 255; | |
const isValidIpAddress = (ipAddress) => { | |
const ipAddressArray = ipAddress.split('.'); | |
return ipAddressArray.length === 4 && ipAddressArray.every(isValid); | |
} |
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 reduceString = (str, targetChar) => { | |
for (let i = str.length - 1; i >= 0; i--) { | |
if (str[i] !== targetChar) continue; | |
i--; | |
while (str[i] === targetChar) { | |
str = str.slice(0, i) + str.slice(i + 1); | |
i--; | |
} |
OlderNewer