made with requirebin
Created
May 27, 2016 06:48
-
-
Save KoryNunn/ba6533370f99e7c7f962149ec6bf9e8b to your computer and use it in GitHub Desktop.
requirebin sketch
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 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; | |
| }); |
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
| 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); |
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
| { | |
| "name": "requirebin-sketch", | |
| "version": "1.0.0" | |
| } |
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
| <!-- contents of this file will be placed inside the <body> --> |
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
| <!-- 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