Skip to content

Instantly share code, notes, and snippets.

@RahmatSaeedi
Last active May 10, 2021 14:19
Show Gist options
  • Save RahmatSaeedi/00c396d927119fcdd179fca6f22ac662 to your computer and use it in GitHub Desktop.
Save RahmatSaeedi/00c396d927119fcdd179fca6f22ac662 to your computer and use it in GitHub Desktop.
CodeSignal - Arcade - Intro - JS - almostIncreasingSequence
function almostIncreasingSequence(sequence) {
let wasAnElementRemoved = false;
for(let i = 0; i<sequence.length-1; i++) {
if(sequence[i] < sequence[i+1]) {
continue;
} else {
if(!wasAnElementRemoved) {
wasAnElementRemoved = true;
if(i==0) {
continue;
} else if(i==sequence.length-2){
return true;
} else {
if(sequence[i] == sequence[i+1] || sequence[i+1]>sequence[i-1] || sequence[i+2] > sequence[i]){
continue;
} else {
return false;
}
}
} else {
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment