Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Generics in Swift Generic Functions, Parameters and Constraints CSS Background Blend Modes Challenge

generic functions with multiple type parameters

i need help with this code challenge. i have been doing all i could and tried my best to pass this challenge, but my code just couldn't be compiled. help please!!!! thanks

generics.swift
func times4(aray: [Int]) -> [Int] {

let size = aray.count - 1
for size in aray {

aray(0...size) * aray(0...size)


}

}






func map<T,U>(array: [T], transformation: (T) -> U) -> [U] {
transformation = times4(array)
return transformation
}

1 Answer

Nathan F.
Nathan F.
30,772 Points

To get started, the code challenge only wants you to create a map<T,U> function with a transformation parameter. Treehouse will test the map function by supplying different arguments to transformation, so you don't need to add a times4 function or call it in your map function.

thanks, got it

Gavin Hobbs
Gavin Hobbs
5,205 Points

aaron du what was your final answer? I can't figure it out. This is my code...

func map<T, U>(array: [T], transformation: (T) -> U) -> U {
    return transformation(array)
}