Created
July 5, 2016 03:12
-
-
Save Tulakshana/e6b6583d397042e77d9dae7533d322c9 to your computer and use it in GitHub Desktop.
A simple set of functions I wrote when having fun with algorithms
This file contains 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
//A function that could be called recursively to calculate the total of an integer array. | |
func total(array:NSArray,index:Int,sum:Int) -> Int { | |
if (index > (array.count - 1)) { | |
return sum | |
}else { | |
let currentNumber:Int = array.objectAtIndex(index) as! Int | |
let currentTotal:Int = sum + currentNumber | |
return total(array, index: index + 1, sum: currentTotal) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment