Last active
December 15, 2022 08:57
-
-
Save vibinnair/a3bd9f7aa714095f34020803632f0811 to your computer and use it in GitHub Desktop.
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
import Foundation | |
func sumOfElements(_ array: [Int], _ sum: Int) -> Int { | |
if array.count <= 0 { | |
return sum | |
} | |
let newArray = Array(array.dropFirst(1)) | |
return sumOfElements(newArray, sum + array.first!) | |
} | |
print("Sum of elements in array is: \(sumOfElements([10, 20, 30], 0))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment