made with requirebin
Created
September 5, 2017 06:45
-
-
Save rokity/375acdb7bf9417c65164be77acf24f22 to your computer and use it in GitHub Desktop.
requirebin sketch
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
// Welcome! require() some modules from npm (like you were using browserify) | |
// and then hit Run Code to run your code on the right side. | |
// Modules get downloaded from browserify-cdn and bundled in your browser. | |
var each = require('foreach-then'); | |
var numbers = [1,2,3]; | |
each(numbers, | |
(item,index,array) => | |
{ | |
//iterate-function | |
}, | |
(array) => | |
{ | |
//then-function | |
}); |
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
setTimeout(function(){ | |
;require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"foreach-then":[function(require,module,exports){ | |
module.exports = (array,iterateFunction,thenFunction)=> | |
{ | |
if(checkArray(array) && checkIterateFunction(iterateFunction) && checkThenFunction(thenFunction)) | |
array.forEach(function(element,index,collection) { | |
iterateFunction(element,index,collection); | |
if(index==collection.length-1) | |
thenFunction(); | |
}); | |
} | |
var checkIterateFunction = (iterateFunction)=> | |
{ | |
if(typeof(iterateFunction)!="function") | |
throw new ForEachException('\'iterate\' isn\'t a function'); | |
else | |
return true; | |
} | |
var checkThenFunction = (thenFunction)=> | |
{ | |
if(typeof(thenFunction)!="function") | |
throw new ForEachException('\'then\' isn\'t a function'); | |
else | |
return true; | |
} | |
var checkArray = (array)=> | |
{ | |
if(typeof(array)!="object") | |
throw new ForEachException('\'array\' isn\'t an array'); | |
else if(array.length>0) | |
return true; | |
else | |
throw new ForEachException('\'array\' is empty'); | |
} | |
function ForEachException(message) { | |
this.message = message; | |
this.name = 'ForEachException'; | |
} | |
},{}]},{},[]) | |
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL2hvbWUvYWRtaW4vYnJvd3NlcmlmeS1jZG4vbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9tb2R1bGVzL2Jyb3dzZXItcGFjay9fcHJlbHVkZS5qcyIsImZvcmVhY2gtdGhlbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6ImdlbmVyYXRlZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIoZnVuY3Rpb24gZSh0LG4scil7ZnVuY3Rpb24gcyhvLHUpe2lmKCFuW29dKXtpZighdFtvXSl7dmFyIGE9dHlwZW9mIHJlcXVpcmU9PVwiZnVuY3Rpb25cIiYmcmVxdWlyZTtpZighdSYmYSlyZXR1cm4gYShvLCEwKTtpZihpKXJldHVybiBpKG8sITApO3ZhciBmPW5ldyBFcnJvcihcIkNhbm5vdCBmaW5kIG1vZHVsZSAnXCIrbytcIidcIik7dGhyb3cgZi5jb2RlPVwiTU9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XG4gICAgICAgIHJldHVybiB0cnVlO1xufVxuXG52YXIgY2hlY2tUaGVuRnVuY3Rpb24gPSAodGhlbkZ1bmN0aW9uKT0+XG57XG4gICAgaWYodHlwZW9mKHRoZW5GdW5jdGlvbikhPVwiZnVuY3Rpb25cIilcbiAgICAgICAgdGhyb3cgbmV3IEZvckVhY2hFeGNlcHRpb24oJ1xcJ3RoZW5cXCcgaXNuXFwndCBhIGZ1bmN0aW9uJyk7XG4gICAgZWxzZVxuICAgICAgICByZXR1cm4gdHJ1ZTtcbn1cblxudmFyIGNoZWNrQXJyYXkgPSAoYXJyYXkpPT5cbntcbiAgICBpZih0eXBlb2YoYXJyYXkpIT1cIm9iamVjdFwiKVxuICAgICAgICB0aHJvdyBuZXcgRm9yRWFjaEV4Y2VwdGlvbignXFwnYXJyYXlcXCcgaXNuXFwndCBhbiBhcnJheScpO1xuICAgIGVsc2UgaWYoYXJyYXkubGVuZ3RoPjApXG4gICAgICAgIHJldHVybiB0cnVlO1xuICAgIGVsc2VcbiAgICAgICAgdGhyb3cgbmV3IEZvckVhY2hFeGNlcHRpb24oJ1xcJ2FycmF5XFwnIGlzIGVtcHR5Jyk7XG59XG5cblxuZnVuY3Rpb24gRm9yRWFjaEV4Y2VwdGlvbihtZXNzYWdlKSB7XG4gICAgdGhpcy5tZXNzYWdlID0gbWVzc2FnZTtcbiAgICB0aGlzLm5hbWUgPSAnRm9yRWFjaEV4Y2VwdGlvbic7XG4gIH1cblxuIl19 | |
// Welcome! require() some modules from npm (like you were using browserify) | |
// and then hit Run Code to run your code on the right side. | |
// Modules get downloaded from browserify-cdn and bundled in your browser. | |
var each = require('foreach-then'); | |
var numbers = [1,2,3]; | |
each(numbers, | |
(item,index,array) => | |
{ | |
//iterate-function | |
}, | |
(array) => | |
{ | |
//then-function | |
}); | |
;}, 0) |
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
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"foreach-then": "1.0.2" | |
} | |
} |
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
<!-- contents of this file will be placed inside the <body> --> |
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
<!-- 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