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 trialBruce G
5,360 PointsWhat is numbers for?
I am bit confused with this problem. I have created the function but what am I suppose to do with the constant "numbers"?
let numbers = [Int](0...50)
// Enter your code below
func isOdd (n: Int) -> Bool {
return numbers % n != 0
}
1 Answer
Holger Liesegang
50,595 PointsHi Bruce!
Challenge Task 2 of 2 "Given an array of integers, called numbers, use the filter function (and the helper function we created) to create a new array containing only odd numbers. Assign this new array to a constant named oddNumbers." asks you to make use of the filter
function as follows:
let numbers = [Int](0...50)
// Enter your code below
func isOdd(i:Int) -> Bool {
return i % 2 != 0
}
let oddNumbers = numbers.filter(isOdd)