Skip to content

Instantly share code, notes, and snippets.

@oliverbth05
Created September 9, 2018 03:25
Show Gist options
  • Save oliverbth05/21ba63ad521d4217bc857e39471e5e7a to your computer and use it in GitHub Desktop.
Save oliverbth05/21ba63ad521d4217bc857e39471e5e7a to your computer and use it in GitHub Desktop.
function almostIncreasingSequence(sequence) {
var i = 0;
var spliced;
function checkValid(arr) {
if (i > sequence.length) {
return false
}
let counter = 0;
for ( var j = 0 ; j < arr.length-1; j ++ ) {
if ( arr[j] < arr[j + 1] ) {
counter ++
}
}
if ( counter === arr.length - 1) {
return true
}
else {
spliced = [...sequence];
spliced.splice(i, 1);
i ++;
return checkValid(spliced);
}
}
return checkValid(sequence)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment