Programming in Swift: Functions & Types, Episode 18: Challenge: filter & reduce | Kodeco

Practice what you have learned about filter, reduce, and sort with this series of hands-on coding challenges.


This is a companion discussion topic for the original entry at https://www.kodeco.com/28433240-programming-in-swift-functions-types/lessons/18

Hi,

I’m getting this error in the console when trying to replicate the Filter exercise.

Value of type ‘String.Element’ (aka ‘Character’) has no member ‘count’.

My code is:

let moreThanFour = names.filter { $0.count > 4 }
print(moreThanFour)

To me seems that all looks good. My Xcode version is 14.1.

Any suggestions?

Thank you,
Elvis

Solved. I wrote .reduce at the end of the main names array and that’s why it was throwing the error.

1 Like