Skip to content

Instantly share code, notes, and snippets.

function add10 (a) {
return a + 10
}
function compound (f) {
return function (b) {
return f(f(b))
}
}
let sentence = ''
function say () {
if ( !arguments[0] ) {
let s = sentence
sentence = ''
return s
} else {
sentence += arguments[0] + ' '
function increment ( numbers ) {
let iterator = numbers.length - 1
while ( iterator >= 0 ) {
let num = numbers[ iterator ]
num++
if (num > 0 && num <= 9) {
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
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'))
}
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'
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)
function formatNumber (num) {
if (typeof num !== 'number') {
console.error('Incorrect value was passed. Please enter a valid number')
return
}
let isNegativeNum
let isFloatingNum
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
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);