We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 114e705 commit 8037094Copy full SHA for 8037094
2243-calculate-digit-sum-of-a-string.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {number} k
4
+ * @return {string}
5
+ */
6
+const digitSum = function(s, k) {
7
+ let cur = s
8
+ while(cur.length > k) {
9
+ const arr = []
10
+ for(let i = 0; i < cur.length; i += k) {
11
+ let tmp = ''
12
+ for(let j = 0; j < k && i + j < cur.length; j++) {
13
+ tmp += cur[i + j]
14
+ }
15
+ arr.push(tmp)
16
17
+ arr.forEach((e, i) => {
18
+ let res = 0
19
+ for(let ch of e) res += +ch
20
+ arr[i] = '' +res
21
+ })
22
+ cur = arr.join('')
23
+
24
25
+ return cur
26
+};
0 commit comments