This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func multiply(arrayInt: [Int]) -> Int { | |
| var result: Int = 1 | |
| for x in arrayInt { | |
| result = x * result | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func sum(arrayInt: [Int]) -> Int { | |
| var result: Int = 0 | |
| for x in arrayInt { | |
| result += x | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func transformStringArray(arrayInt: [Int], transform: Int -> String) -> [String] { | |
| var result: [Int] = [] | |
| for x in arrayInt { | |
| result.append(transform(x)) | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addOne(arrayInt: [Int]) -> [Int] { | |
| return transformArray(arrayInt) { x in | |
| x + 1 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func transformArray(arrayInt: [Int], transform: Int -> Int) -> [Int] { | |
| var result: [Int] = [] | |
| for x in arrayInt { | |
| result.append(transform(x)) | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func addArray(arrayInt: [Int]) -> [Int] { | |
| var result: [Int] = [] | |
| for x in arrayInt { | |
| result.append(x + 1) | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func multiplyArray(arrayInt: [Int]) -> [Int] { | |
| var result: [Int] = [] | |
| for x in arrayInt { | |
| result.append(x * 2) | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array { | |
| func filterr(includeElement: Element -> Bool) -> [Element] { | |
| var result: [Element] = [] | |
| for x in self where includeElement(x) { | |
| result.append(x) | |
| } | |
| return result | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func isOdd(arrayInt: [Int]) -> [Int] { | |
| var result: [Int] = [] | |
| for x in arrayInt { | |
| if x % 2 != 0 { | |
| result.append(x) | |
| } | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Changed the name to mapp to clarify that's our own map in Xcode (or playground). | |
| extension Array { | |
| func mapp<T>(transform: Element -> T) -> [T] { | |
| var result: [T] = [] | |
| for x in self { | |
| result.append(transform(x)) | |
| } | |
| return result | |
| } | |
| } |