Returns the Integers for which a number is divisible by within a specified Array in Swift
//returns an array of integers that are divisible by num, within a parameter array
var DivisibleFilter = {(num:Int, divisor:Int) ->Bool in num % divisor == 0}
var DivisibleInRange = {(num:Int, list:Array<Int>) ->Array<Int> in var divlist = [Int]()
for element in list {
if DivisibleFilter(element, num) == true {
divlist.append(element)
}
}
return divlist
}
DivisibleInRange(3, [3, 4, 5, 6, 7, 8, 9, 12, 15, 18])
// returns [3, 6, 9, 12, 15, 18]