File tree 1 file changed +9
-12
lines changed
1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * RLE (Run Length Encoding) is a simple form of data compression.
3
- * The basic idea is to represent repeated successive characters as a single count and character.
4
- * For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".
5
- *
6
- * @author - [ddaniel27](https://github.com/ddaniel27)
7
- */
2
+ * RLE (Run Length Encoding) is a simple form of data compression.
3
+ * The basic idea is to represent repeated successive characters as a single count and character.
4
+ * For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".
5
+ *
6
+ * @author - [ddaniel27](https://github.com/ddaniel27)
7
+ */
8
8
9
9
function Compress ( str ) {
10
10
let compressed = ''
@@ -27,15 +27,12 @@ function Decompress(str) {
27
27
let decompressed = ''
28
28
let match = [ ...str . matchAll ( / ( \d + ) ( \D ) / g) ] // match all groups of digits followed by a non-digit character
29
29
30
- match . forEach ( item => {
30
+ match . forEach ( ( item ) => {
31
31
let [ count , char ] = [ item [ 1 ] , item [ 2 ] ]
32
32
decompressed += char . repeat ( count )
33
33
} )
34
34
35
- return decompressed
35
+ return decompressed
36
36
}
37
37
38
- export {
39
- Compress ,
40
- Decompress
41
- }
38
+ export { Compress , Decompress }
You can’t perform that action at this time.
0 commit comments