iOS Closures in Swift Building Standard Library Functions Using Filter

STEVEN PENA
STEVEN PENA
13,778 Points

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 143,684 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 }