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
var m = [ | |
'Monday', | |
'Tuesday', | |
'Wednesday', | |
'Thursday', | |
'Friday', | |
'Saturday', | |
'Sunday' | |
] | |
const N = [].concat( |
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
function insert (node, x) { | |
if (x < node.value) { | |
if (node.left) { | |
if (x < node.left.value) { | |
insert(node.left, x) | |
} else { | |
node.left = {value: x, left: node.left} | |
} | |
} else { | |
node.left = {value: x} |
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
function replace_without_case_sensitive (where, from, to) { | |
return where.toLowerCase().split(from.toLowerCase()).reduce( | |
(acc, _) => | |
[ | |
acc[0] + _.length + from.length, | |
acc[1].concat(where.substring(acc[0], acc[0] + _.length)) | |
], | |
[0, []] | |
)[1].join(to) | |
} |
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
function cellCompete(states, days) { | |
if (days === 0) return states | |
const a = new Array(states.length) | |
states.push(0) | |
states.unshift(0) | |
for (var i = 1; i < states.length - 1; i++) | |
a[i - 1] = states[i - 1] === states[i + 1] | |
? 0 | |
: 1 | |
return cellCompete(a, days - 1) |
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
var deferred = require('deferred'); | |
var assert = require('assert'); | |
describe('deferred', function () { | |
it('map', function (done) { | |
var def1 = deferred(); | |
var def2 = deferred(); | |
setTimeout(function () { | |
def1.resolve(1); |
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
new Promise((y, n) => redis((e, db) => e ? n(e) : y(db))) |
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
var i = 0; | |
var bigest = (bytes) => { | |
console.log(i++, bytes); | |
try { | |
return new ArrayBuffer(bytes) | |
} catch (e) { | |
return bigest(bytes / 2) | |
} | |
} |
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
/*Question 1: Sum to 100 | |
Write a function that, given a string of digits, build an expression such that the digits will sum to 100 by inserting +, - anywhere between the digits. | |
For example, given the input 123456789, one such expression is 1 + 23 - 4 + 5 + 6 + 78 - 9 = 100 | |
Your function should return all possible combinations. | |
*/ | |
var results = {}; | |
function calc(n, s, part) { | |
if (n === 0 && s === '' && part[0] !== '-') return results[part.substring(1)] = null |
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
var fs = require('fs'); | |
var AVLTree = require('avl'); | |
var tree = new AVLTree(); | |
var map = fs.readFileSync('map.txt', 'utf-8').split('\n').map(l => l.split(' ').map(c => Number(c))); | |
var [I, J] = map.shift(); | |
var result = { | |
path: 0, | |
drop: 0 | |
}; |
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
var | |
fetch = require('node-fetch'), | |
md5 = require('md5'), | |
md5s = ["e4820b45d2277f3844eac66c903e84be", "23170acc097c24edb98fc5488ab033fe", "665e5bcb0c20062fe8abaaf4628bb154"], | |
match_md5 = frase => md5s.indexOf(md5(frase)) !== -1, | |
word2map = word => word.split('').reduce((acc, c) => {acc[c] = acc[c] || 0; acc[c]++; return acc}, {}), | |
match = rm => word => { | |
var char, i = 0, wm = {}; | |
while (i < word.length) { | |
char = word[i]; |
NewerOlder