Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@buzzdecafe
buzzdecafe / dedupe with reduce
Last active December 16, 2015 05:59
dedupe an array of objects
// Paul's clean-up
function deDupe(dupeCheck, list) {
return list.reduce(function (prev, curr) {
if (!dupeCheck(curr, prev)) {
prev.push(curr);
}
return prev;
}, []);
}
@buzzdecafe
buzzdecafe / aaa.js
Last active December 15, 2015 17:29 — forked from AutoSponge/tco.md
function recur(fn) {
return function () {
var bounce = fn.apply(this, arguments);
while (bounce.onTheTrampoline) {
bounce = bounce();
}
return bounce;
};
}
var sum1 = recur(function sum(x, y) {
@buzzdecafe
buzzdecafe / cons, car, cdr
Last active November 17, 2021 10:11
cons car and cdr implemented as javascript functions. cribbed from SICP http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_thm_2.4then implemented a bunch of functions just for fun.
// clean and pure:
function cons(x, y) {
return function(pick) {
return pick(x, y);
}
}
// does more stuff:
function cons(x, y) {
var fn = function(pick) {