Skip to content

Instantly share code, notes, and snippets.

@saru2020
Created May 20, 2019 07:51
Show Gist options
  • Save saru2020/69a32ebff4e42fe1a55834db4fa4e3f4 to your computer and use it in GitHub Desktop.
Save saru2020/69a32ebff4e42fe1a55834db4fa4e3f4 to your computer and use it in GitHub Desktop.
//Functional Programming
func sum(start: Int, end: Int, total: Int) -> Int {
if (start > end) {
return total;
}
return sum(start: start + 1, end: end, total: total + start)
}
print("Functional: total: ", sum(start: 1, end: 10, total: 0)); // prints 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment