Write a Ruby program to count the number of 5's in a given array.
def array_count(array) count = 0 array.each{|item| count += 1 unless item != 5} return count end print array_count([1, 2, 9]),"\n" print array_count([1, 2, 5, 9]),"\n" print array_count([1, 2, 5, 9, 5])
Output:
0 1 2
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer