Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Closures in Swift Building Standard Library Functions Using Filter

Stanislav Zaichenko
seal-mask
.a{fill-rule:evenodd;}techdegree
Stanislav Zaichenko
iOS Development with Swift Techdegree Student 4,929 Points

Why this would not pass the code challenge?

let numbers = [10,423,802,765,943,12,405,230,1348,128,237] let oddValues = numbers.filter { $0 % 3 == 0 } oddValues // [423, 765, 12, 405, 237] what appears in my sandbox

filter.swift
let numbers = [10,423,802,765,943,12,405,230,1348,128,237]
let oddValues = numbers.filter { $0 % 3 == 0 } 

1 Answer

Your predicate is numbers that are perfectly divisible by 3. So for the array this will include for example 12 which is perfectly divisible by 3 but not odd. The video @ 0:56 shows how to use filter for even numbers with { 0 % 2 == 0}. Odd numbers would be where this isn't the case { 0 % 2 != 0} or { 0 % 2 == 1}.