Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Created May 27, 2016 06:48
Show Gist options
  • Select an option

  • Save KoryNunn/ba6533370f99e7c7f962149ec6bf9e8b to your computer and use it in GitHub Desktop.

Select an option

Save KoryNunn/ba6533370f99e7c7f962149ec6bf9e8b to your computer and use it in GitHub Desktop.
requirebin sketch
var items = [1,2,3,-4,3,6,2,1,7,3,4,2,4],
ids = Object.keys(items);
function loadItem(id, callback){
setTimeout(function(){
if(!(id in items)){
return callback('Not Found');
}
callback(null, items[id]);
}, 100);
}
function findNegative(items, callback){
if(!items.length){
callback();
}
loadItem(items[0], function(error, result){
if(error){
return callback(error);
}
if(result < 0){
return callback(null, result);
}
findNegative(items.slice(1), callback);
});
}
findNegative(ids, function(error, result){
document.body.innerText += result;
});
setTimeout(function(){var items=[1,2,3,-4,3,6,2,1,7,3,4,2,4],ids=Object.keys(items);function loadItem(id,callback){setTimeout(function(){if(!(id in items)){return callback("Not Found")}callback(null,items[id])},100)}function findNegative(items,callback){if(!items.length){callback()}loadItem(items[0],function(error,result){if(error){return callback(error)}if(result<0){return callback(null,result)}findNegative(items.slice(1),callback)})}findNegative(ids,function(error,result){document.body.innerText+=result})},0);
{
"name": "requirebin-sketch",
"version": "1.0.0"
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment