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
'use strict'; | |
// core modules | |
var assert = require('assert'); | |
module.exports = function(map) { | |
var keys = Object.keys(map); | |
return Promise.all(keys.map(function(mapKey) { | |
return map[mapKey]; |
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
I - J - K - L - G - H - I | |
/ \ / \ / \ / \ / \ / \ / \ | |
F - A - B - C - D - E - F - A | |
\ / \ / \ / \ / \ / \ / \ / \ | |
L - G - H - I - J - K - L - G | |
\ / \ / \ / \ / \ / \ / \ / | |
D - E - F - A - B - C - D | |
F - G - H - E - F |
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
'use strict'; | |
var assert = require('assert'); | |
module.exports = function(createDefaultValue) { | |
var map = {}; | |
var keyValuePairs = []; | |
var lookup = function(key) { |
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 loadScript = function(src) { | |
return new Promise(function(resolve, reject) { | |
var scriptTag = document.createElement('script'); | |
scriptTag.src = src; | |
document.body.appendChild(scriptTag); | |
scriptTag.addEventListener('load', function() { | |
console.log('loaded', src); | |
resolve(); |
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
'use strict'; | |
var bignum = require('bignum'); | |
var fib = function(n) { | |
var a = bignum(0); | |
var b = bignum(1); | |
for (var i = 1; i < n; i++) { | |
a = a.add(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
var magicRequire = function(moduleName) { | |
return new Promise(function(resolve, reject) { | |
var scriptTag = document.createElement('script'); | |
scriptTag.src = 'https://www.brcdn.org/' + moduleName + '/latest'; | |
document.body.appendChild(scriptTag); | |
scriptTag.addEventListener('load', function() { | |
if (!window.require) { | |
reject(new Error('require function not found')); |
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
'use strict'; | |
module.exports = function(loop) { | |
return (function cycle(result) { | |
return result || loop().then(cycle); | |
})(); | |
}; |
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 enumerateChoices = (sets) => { | |
if (sets.length === 0) { | |
return [[]]; | |
} | |
const subChoices = enumerateChoices(sets.slice(1)); | |
return [].concat(...sets[0].map( | |
choice => subChoices.map(choices => [choice].concat(choices)) | |
)); |
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
reduce = [init, arr, combine] => match(arr) { | |
[head, tail...] => ( | |
reduce([combine([init, head]), tail, combine]) | |
); | |
[] => ( | |
init | |
); | |
}; |
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
'use strict'; | |
const assert = (x) => { | |
if (!x) { | |
throw new Error('Assertion failure'); | |
} | |
}; | |
const range = (n) => (new Array(n)).fill(0).map((x, i) => i); |