Skip to content

Instantly share code, notes, and snippets.

@julien-sarazin
Last active March 10, 2016 01:23
Show Gist options
  • Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
Save julien-sarazin/a3704e698f2874d89b45 to your computer and use it in GitHub Desktop.
to-beer-ornot-to-beer
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!'
}
}
@Zae
Copy link

Zae commented Mar 8, 2016

I kept getting the error that the then method did not exist on the promise that was returned by the drink() method :(

@neolectron
Copy link

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.

@evannieuwburg
Copy link

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 ;-)

@julien-sarazin
Copy link
Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment