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 _ = (function() { | |
var _ = { | |
curry: curry, | |
compose: compose | |
}; | |
return _; | |
function realArgumentCount(unreal, args) { |
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
/* | |
Let `a` be a Promise. To make the generator wait for a to resolve, | |
simply `yield a`. By default, all rejected Promises throw an error | |
in our generator. Yield an iteratable to get an array of resolved | |
values. | |
*/ | |
function isIterable(object) { | |
return Symbol.iterator in Object(object); | |
} |
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 memoize(object, name, descriptor) { | |
var fn = descriptor.value; | |
var memoized = function() { | |
memoized.cache = memoized.cache || {}; | |
var key = JSON.stringify(arguments); | |
return memoized.cache[key] = memoized.cache[key] | |
? memoized.cache[key] | |
: fn.apply(this, arguments); | |
} | |
descriptor.value = memoized; |
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
export const _ = Symbol(); | |
export function curry(fn) { | |
return function func(...args) { | |
if (countRealArguments(_, args) < fn.length) { | |
return function inner(...innerArgs) { | |
return this::func(...merge(_, args, innerArgs)) | |
} | |
} else { | |
return this::fn(...args); |
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 curry = (function() { | |
return curry; | |
function isObject(thing) { | |
return Object(thing) === thing; | |
} | |
function isEmpty(object) { | |
return isObject(object) && ! Object.keys(object).length; |
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 fibonacci(n) { | |
return (function loop(i, f0, f1) { | |
return i === 0 ? f0 : loop(i - 1, f1, f0 + f1); | |
})(n, 0, 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
/** | |
* A Tree is an Object that may contain other Trees, Objects, Promises, | |
* or primitives. By definition, it contains no cycles. | |
* @typedef [Object] Tree | |
*/ | |
/** | |
* @function tree | |
* @memberof Promise | |
* @param [Tree] tree |
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
console.log(quickSort([2,1,4,3])); | |
console.log(quickSort(randomInts(20))); | |
function randomInts(n) { | |
return Array.apply(null, Array(n)).map(() => Math.floor(Math.random() * n)); | |
} | |
function quickSort(array) { | |
return quickSortLists([array]); | |
} |
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
(defn quick-sort-lists [lists] | |
(lazy-seq | |
(loop [[selected & other-lists] lists] | |
(cond (seq selected) | |
(let [[pivot & selected-others] selected | |
smaller-than-pivot? #(< %1 pivot)] | |
(recur (list* (filter smaller-than-pivot? selected-others) | |
pivot | |
(remove smaller-than-pivot? selected-others) | |
other-lists))) |
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
(defn my-filter [predicate? collection] | |
(lazy-seq | |
(loop [[head & tail] collection] | |
(if (predicate? head) | |
(cons head (my-filter predicate? tail)) | |
(if (seq tail) | |
(recur tail) | |
()))))) |
OlderNewer