Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let someArray = [1, 12, 123, 110, 1245, 20, 1, 6]
- func filterArrray(array: [Int], condition: (Int) -> (Bool)) -> [Int] {
- var filteredArray: [Int] = []
- for arrayElement in array {
- if condition(arrayElement) {
- filteredArray.append(arrayElement)
- }
- }
- return filteredArray
- }
- func firstFunc(number: Int) -> Bool {
- return (number > 100) && (number < 200)
- }
- let firstResult = filterArrray(array: someArray, condition: firstFunc)
- let secondResult = filterArrray(array: someArray, condition: { (element) -> (Bool) in
- return element % 10 == 0
- })
- let thirdResult = filterArrray(array: someArray) { (element) -> (Bool) in
- return element != 1
- }
- print(firstResult)
- print(secondResult)
- print(thirdResult)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement