Created
July 18, 2015 05:18
-
-
Save jweinst1/ef1fb0b3cc5ae57926cd to your computer and use it in GitHub Desktop.
In swift, closures that take the count, sum, and mean of an array in swift.
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
// sums all the integers in an array | |
var ArraySum = {(var list:Array<Int>) -> Int in | |
var sum = 0 | |
for element in list { | |
sum += element | |
} | |
return sum | |
} | |
// uses a for loop to count the integers in an array | |
var ArrayCount = {(var list:Array<Int>) -> Int in | |
var sum = 0 | |
for element in list { | |
sum += 1 | |
} | |
return sum | |
} | |
// takes the mean of an integer array | |
var Arraymean = {(var list:Array<Int>) -> Int in ArraySum(list)/ArrayCount(list)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment