Reputation: 3163
In Swift how would I iterate through the NSMutableArray of ints var numbers = [4,5,5,4,3]
and count how many are equal to 5?
Upvotes: 0
Views: 144
Reputation: 8164
You can use reduce
for this:
let array = [4,5,5,4,3]
let fives = array.reduce(0, combine: { $0 + Int($1 == 5) })
Upvotes: 4