Skip to content

Instantly share code, notes, and snippets.

// Example args
const filters = ['LOWER_LETTERS', 'NUMS'];
const pwLength = 5;
// ******************************************
/**
* @param {number} pwLength
* @param {string []} filters
* @return {string}
// Example args
const filters = ['LOWER_LETTERS', 'NUMS'];
const pwLength = 5;
// ******************************************
/**
* @param {number} pwLength
* @param {string []} filters
* @return {string}
@patrickxrivera
patrickxrivera / Delete Node from Binary Search Tree Recursively in JavaScript
Last active May 27, 2018 03:06
Simple recursive algorithm for deleting any node in a binary search tree.
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;
/**
* @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++) {
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);
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);
const readline = require('readline');
console.log('Welcome to Guessing Game!');
const Terminal = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const App = {
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);
const isValid = (address) => address >= 0 && address <= 255;
const isValidIpAddress = (ipAddress) => {
const ipAddressArray = ipAddress.split('.');
return ipAddressArray.length === 4 && ipAddressArray.every(isValid);
}
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--;
}