How to implement array.any() and array.all() methods in Coffeescript?
How to implement array.any() and array.all() methods in Coffeescript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Those are actually part of Javascript 1.6 and will work just the same in CoffeeScript. You want some and every.
I don’t know what environment you’re in, but IE < 9 doesn’t seem to support those methods. They’re pretty easy to add. There’s a snippet of code on those pages that show you compatibility code and if you want you can translate them to CoffeeScript, though you don’t have to.
A cruder, simpler way would be (untested):
But neither of those have short circuit logic. Edit: But see Ricardo’s answer for a better version of them.