Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Created July 5, 2016 03:12
Show Gist options
  • Save Tulakshana/e6b6583d397042e77d9dae7533d322c9 to your computer and use it in GitHub Desktop.
Save Tulakshana/e6b6583d397042e77d9dae7533d322c9 to your computer and use it in GitHub Desktop.
A simple set of functions I wrote when having fun with algorithms
//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