Swift solution 1 while 1 for 1 if
 # Intuition  \n\n\n\n\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(n)\n\n\n# Code\nswift []\nclass Solution {\n    func digitSum(_ s: St
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```swift []\nclass Solution {\n    func digitSum(_ s: String, _ k: Int) -> String {\n        var res = Array(s) \n\n        while res.count > k {\n            var newStr = ""\n            var currSum = 0\n\n            for i in 0..<res.count {\n                currSum += res[i].wholeNumberValue ?? 0\n\n                if (i + 1) % k == 0 || i == res.count - 1 {\n                    newStr.append("\\(currSum)")\n                    currSum = 0\n                }\n            }\n            res = Array(newStr)\n        }\n        return String(res)\n    }\n}\n```
['Swift']