Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- func sumOfDigits(a: Int) -> Int {
- let string = String(a)
- let i = string.components(separatedBy: " ")
- let z = Array(string)
- let sum = z.reduce(0, +)
- for i in string {
- }
- return z
- }
- //sumOfDigits(a: 23) // returns 5
- //sumOfDigits(a: 496) // returns 19
- //func sumOfDigits(a: Int) -> Int {
- // // let string = String(a)
- // let i = a.components(separatedBy: " ")
- // // let z = Array(string)
- // let z = i.reduce(0, +)
- // // for i in string {
- //
- // // }
- // return z
- //}
Add Comment
Please, Sign In to add comment