Skip to content

Commit 0c7ebe1

Browse files
author
Reza Rafsanjani
committed
fix issue akshitagit#17
1 parent a292255 commit 0c7ebe1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Algorithms/compressString.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function compressString(str) {
2+
var chars = str.split("");
3+
var compressed = '';
4+
var count = 0;
5+
chars.forEach((c,i) => {
6+
count++;
7+
if (c != chars[i+1]) {
8+
compressed += c + count;
9+
count = 0;
10+
}
11+
})
12+
return compressed;
13+
}

0 commit comments

Comments
 (0)