-
-
Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
function drink(Promise, friend, pints){ | |
var count = 0; | |
var promises = pints.map(function(pint){ | |
return friend | |
.drink() | |
.then(increaseCount) | |
.catch(reject); | |
}); | |
return Promise.all(promises) | |
.then(congrats); | |
function increaseCount(){ | |
count ++; | |
} | |
function reject(){ | |
return Promise.reject('Damn ' + friend.name + '! You stopped after ' + count + ' pints!'); | |
} | |
function congrats(){ | |
return "Congratulation to " + friend.name + "! You drank " + pints.length + ' pints! Hura!' | |
} | |
} |
Time you should consider telling us Promise is bluebird next time 👍
It can save us a small amount of time by console.log-ing your Promise Object here.
To figure-out what it was, their console.error gave me an url pointing to Bluebird documentation.
The description of the challenge was pretty poorly documented. Everyone around me was staring and fiddling, but not really knowing what to solve exactly. Maybe next time just share the test cases instead of a written description ;-)
@Zae means the function drink
you wrote wasn't returning a promise.
@neolectron Totally agree on that, i will next time, thanks for sharing.
@evannieuwburg agree on that too, would be nice. We'll think about it, see if it could be easily integrated for the next release.
Thanks a lot guys for your feedback!
I kept getting the error that the then method did not exist on the promise that was returned by the drink() method :(