Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View 0-conditional-iteration.js
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");
});
View 0-conditional-iteration.js
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

This was linked from the Q library examples. I'm not really sure how this solves the problem of breaking out of a promise chain. Can you explain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.