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

Apply the filter function on the numbers array provided to end up with an array of odd Assign the value to a c

i need a little help

filter.swift
let numbers = [10,423,802,765,943,12,405,230,1348,128,237]
let oddNumbers = (0...100).filter { $0 % 2 == 0 }

3 Answers

Here is a correct solution. I figured that out.

let numbers = [10,423,802,765,943,12,405,230,1348,128,237]
let oddValues = numbers.filter { $0 % 2 != 0 }
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Steven,

Challenges are very specific and very picky. Instructions must be followed exactly or the Tasks will not pass. Also, what is taught in the videos is often only related in concept to the challenges, so code from the videos will not work in the challenges. It looks like you are using code from the video, and didn't read the instructions carefully enough.

There are 3 errors that are preventing you from passing the Task:

  1. The task specifically says to "Apply the filter function to the numbers array, but you have created a range of numbers (which was not asked for) and are applying the filter to that instead of the array provided by the challenge
  2. The task says to apply the value to a constant named "oddValues" ... but yours is named "oddNumbers"
  3. The task wants an array of odd numbers, but you are checking for and assigning the even numbers

If you fix those up the challenge will pass.

Keep Coding! :) :dizzy:

We assign to oddNumbers because engine throws an error saying that you should assign the result to a constant named OddNumbers. So, what's wrong?

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