Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 643 Bytes

counting_sheep.md

File metadata and controls

25 lines (20 loc) · 643 Bytes

Description

Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

For example,

[true,  true,  true,  false,\
true,  true,  true,  true ,\
true,  false, true,  false,\
true,  false, false, true ,\
true,  true,  true,  true ,\
false, false, true,  true]

The correct answer would be 17.

Hint: Don't forget to check for bad values like null/undefined

My Solution

def countSheeps(array)
  array.count(true)
end