Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lestoni
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestoni/cc02e429400463b45e88 to your computer and use it in GitHub Desktop.
Save lestoni/cc02e429400463b45e88 to your computer and use it in GitHub Desktop.
Cruncher.js
function cruncher(fn, context){
if(typeof fn !== 'function'){
return new Error('Expected ' + fn + ' to be a function');
}
var _slice = [].slice,
memo = [];
function ingest(){
memo.push(fn.apply(context || null, _slice.call(arguments)));
}
function out(){
return memo.splice(0, memo.length);
}
return {
ingest: ingest,
out: out
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment