public
Last active

  • Download Gist
0-conditional-iteration.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var callbacks = Array.prototype.forEach.call(
"abcdefg",
function (letter) {
// or some expensive computation
return letter;
}
);
 
return callbacks.reduceRight(function (otherwise, callback) {
var letter = callback();
if (letter === "h") {
return letter;
} else {
return otherwise();
}
}, function () {
throw new Error("Can't find H");
});
1-flow.txt
1 2 3 4
A->B->C->D->E->F->G->otherwise
| | | | | | |
v v v v v v v
a b c d e f g

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.