Created
April 16, 2021 14:19
-
-
Save mingkyme/0cb541e611efb47d90f73c934ebe636f 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
var list = [1,2,5,7,9,10,11,15,16,17]; | |
var result = ""; | |
var tempCount = 0; | |
for(var i=0;i<list.length-1;i++){ | |
if(list[i]+1 == list[i+1]){ | |
tempCount++; | |
}else{ | |
if(tempCount > 0){ | |
result += tempCount.toString(); | |
tempCount = 0; | |
} | |
} | |
} | |
if(tempCount > 0){ | |
result += tempCount.toString(); | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment