MIni-exercises Chapter 8 page 162

I cannot get reduce to chain with filter. What am I doing wrong? Here’s my code:

let names = [“Larry”, “Nancy”, “Chet”, “Heather”, “Trey”, “Rocco”]

let chained = names.filter{$0.count > 4}.reduce(into: String()) {
result, name in
result += name
}

The playground complains;
error: MyPlayground.playground:6:42: error: cannot invoke ‘reduce’ with an argument list of type ‘(into: String, (_, _) -> _)’
let chained = names.filter{$0.count > 4}.reduce(into: String()) {

But when I do it separately, this works:

let longNames = names.filter {$0.count > 4}

let allNames = longNames.reduce(into: String()) {
result, name in
result += name
}

Nevermind, I found my answer in the downloads. I didn’t realize that was where all the solutions were.

This topic was automatically closed after 166 days. New replies are no longer allowed.