Created
July 18, 2016 00:38
-
-
Save dstyle0210/37b8c25be76f5a273c153b8f990b4803 to your computer and use it in GitHub Desktop.
[코딩도장] 문자열 압축하기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 코딩도장 공부 : 문자열 압축하기 | |
| // http://codingdojang.com/scode/465 | |
| var data = "aaabbcccccca"; | |
| var str = ""; | |
| var num = 1; | |
| var target = ""; | |
| data.split("").forEach(function(item){ | |
| if(target!=item){ | |
| str += (target!="") ? target+""+num : ""; | |
| target = item; | |
| num = 1; | |
| }else{ | |
| num++; | |
| } | |
| }); | |
| console.log(str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment