/ Published in: Ruby
Need a way to count the number of non empty strings in an array?
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def non_empty_string_count(array) array.inject(0) {|count,a| count += (a && a.length > 0 ? 1 : 0)} end