Task

Take a combined set of elements and apply a function to each element.




func Array.Select(pred) {
    let ys = []
    for x in this when pred(x) {
        ys.Add(x)
    }
    return ys
}
 
var arr = [1, 2, 3, 4, 5]
var squares = arr.Select(x => x * x)
 
print(squares)