Guest User

Untitled

a guest
Dec 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import UIKit
  2.  
  3. func sumOfDigits(a: Int) -> Int {
  4. let string = String(a)
  5. let i = string.components(separatedBy: " ")
  6. let z = Array(string)
  7. let sum = z.reduce(0, +)
  8. for i in string {
  9.  
  10. }
  11. return z
  12. }
  13.  
  14. //sumOfDigits(a: 23) // returns 5
  15. //sumOfDigits(a: 496) // returns 19
  16.  
  17.  
  18.  
  19.  
  20.  
  21. //func sumOfDigits(a: Int) -> Int {
  22. // // let string = String(a)
  23. // let i = a.components(separatedBy: " ")
  24. // // let z = Array(string)
  25. // let z = i.reduce(0, +)
  26. // // for i in string {
  27. //
  28. // // }
  29. // return z
  30. //}
Add Comment
Please, Sign In to add comment