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 add10 (a) { | |
return a + 10 | |
} | |
function compound (f) { | |
return function (b) { | |
return f(f(b)) | |
} | |
} |
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
let sentence = '' | |
function say () { | |
if ( !arguments[0] ) { | |
let s = sentence | |
sentence = '' | |
return s | |
} else { | |
sentence += arguments[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 increment ( numbers ) { | |
let iterator = numbers.length - 1 | |
while ( iterator >= 0 ) { | |
let num = numbers[ iterator ] | |
num++ | |
if (num > 0 && num <= 9) { |
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 twoDiff(arr, target) { | |
let map = {} | |
for (let i = 0; i < arr.length; i++) { | |
let sub = arr[i] - target | |
let add = arr[i] + target | |
if ( map[sub] || map[add] ) { | |
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
function customSetInterval (cb, interval) { | |
return setTimeout( () => { | |
if (typeof cb == 'function') { | |
cb() | |
// Recurse | |
customSetInterval(cb, interval) | |
} else { | |
console.error(new Error('Expecting a function as a callback')) | |
} |
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 BOARD_SIZE = 3 | |
// For 3 * 3 board, stateOfTheGame = [row1, row2, row3, col1, col2, col3, diag1, diag2] | |
let stateOfTheGame = new Array(BOARD_SIZE * 2 + 2) | |
//Initialize the board with zero | |
stateOfTheGame.fill(0) | |
function isTicTacToeWon (row, column, player) { | |
// We will use -1 for 'ZERO' and +1 for player 'EX' |
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 hexToRGB (hex) { | |
// remove whitespace from left and rihgt ends | |
hex = hex.trim() | |
if (hex.startsWith('#')) { | |
hex = hex.replace('#', '') | |
} | |
// convert short hand notation (f0f) to the regular notation (ff00ff) |
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 formatNumber (num) { | |
if (typeof num !== 'number') { | |
console.error('Incorrect value was passed. Please enter a valid number') | |
return | |
} | |
let isNegativeNum | |
let isFloatingNum |
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 isZeroArr(arr) { | |
if (!arr.length) return false | |
for (let i = 0; i < arr.length - 1; i++) { | |
if (arr[i] != 0) return false; | |
} | |
return true; | |
} | |
function isPossible(row, folks) { | |
var rowLen = row.length |
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
var BST = new BinarySearchTree(); | |
BST.insertNode(8); | |
BST.insertNode(3); | |
BST.insertNode(10); | |
BST.insertNode(1); | |
BST.insertNode(6); | |
BST.insertNode(14); | |
BST.insertNode(4); |