Last active
May 10, 2021 14:19
-
-
Save RahmatSaeedi/00c396d927119fcdd179fca6f22ac662 to your computer and use it in GitHub Desktop.
CodeSignal - Arcade - Intro - JS - almostIncreasingSequence
This file contains 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
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