Is there some method in coffeescript that returns true when an array has some items in it? Like method in ruby present?
:
[].present? false
[1].present? true
According to http://arcturo.github.com/library/coffeescript/07_the_bad_parts.html an array emptiness in coffeescript is determined by its length
alert("Empty Array") unless [].length
that seems so lame to me.
I don't think there is but can be:
Array::present = ->
@.length > 0
if [42].present()
# why yes of course
else
# oh noes
A very simple and incomplete implementation but it should give you some ideas. And for the record, there's no present?
method in Ruby, the method is added by the active_support
gem.
Unfortunately, there isn't. The best way to do it is by comparing its length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With