Skip to content

Instantly share code, notes, and snippets.

@mingkyme
Created April 16, 2021 14:19
Show Gist options
  • Save mingkyme/0cb541e611efb47d90f73c934ebe636f to your computer and use it in GitHub Desktop.
Save mingkyme/0cb541e611efb47d90f73c934ebe636f to your computer and use it in GitHub Desktop.
연속된 숫자 갯수 확인
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