func repeat<ItemType>(item: ItemType, times: Int) -> ItemType[]
{
var result = ItemType[]()
for i in 0..times
{
result += item
}
return result
}
println(repeat("knock3",4))
func repeatArray<arrayItem>(item: arrayItem,times: Int) -> arrayItem[]
{
var rel = arrayItem[]()
for i in 0..times
{
rel += item
}
return rel
}
println(repeatArray("sunxin",5))
var arr = repeatArray("sunxin",15)
println(arr)
func anyCommonElements <T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> (lhs: T, rhs: U) -> Bool {
for lhsItem in lhs {
for rhsItem in rhs {
if lhsItem == rhsItem {
return true
}
}
}
return false
}
println("************************")
println(anyCommonElements([1, 13, 13], [3]))
func anyCommonElements1 <T1, U2 where T1: Sequence, U2: Sequence, T1.GeneratorType.Element: Equatable, T1.GeneratorType.Element == U2.GeneratorType.Element> (lhsff: T1, rhs: U2) -> Bool {
for lhsItem in lhsff {
for rhsItem in rhs {
if lhsItem == rhsItem {
return true
}
}
}
return false
}
println("************************")
println(anyCommonElements([1, "1a3", 13], ["1a3"]))