Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,8 @@
let haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
for needle in ["Washington","Bush"] {
if let index = haystack.indexOf(needle) {
print("\(index) \(needle)")
} else {
print("\(needle) is not in haystack")
}
}

View file

@ -0,0 +1,8 @@
let haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
for needle in ["Washington","Bush"] {
if let index = find(haystack, needle) {
println("\(index) \(needle)")
} else {
println("\(needle) is not in haystack")
}
}

View file

@ -0,0 +1,20 @@
// the second part can be done several ways, but extending any Array of Comparable objects is the most generic approach
extension Array where Element : Comparable {
func lastIndexMatching(needle:Element) -> Int? {
for i in stride(from: count-1, through: 0, by: -1) {
if self[i] == needle {
return i
}
}
return nil
}
}
for needle in ["Washington","Bush"] {
if let index = haystack.lastIndexMatching(needle) {
print("\(index) \(needle)")
} else {
print("\(needle) is not in haystack")
}
}