This commit is contained in:
2020-02-17 22:23:21 +01:00
parent 8e45aba7a3
commit 14232e3225
5 changed files with 71 additions and 76 deletions

View File

@@ -5,20 +5,20 @@ eller så må vi ta vekk det andre, men vi står fortsatt alltid igjen med ett a
*/
function almostIncreasingSequence(sequence) {
let decreaseCounter=0;
for (elements in sequence){
if (sequence[elements] > sequence[parseInt(elements)+1]) {
decreaseCounter++;
if (decreaseCounter > 1) {
return false;
}
}
let decreaseCounter = 0;
for (elements in sequence){
if (sequence[elements] > sequence[parseInt(elements) + 1]) {
decreaseCounter++;
if (decreaseCounter > 1) {
return false;
}
}
return true;
}
return true;
}
/* Test */
console.log("[1,3,2,1]" + " -> " + almostIncreasingSequence([1,3,2,1]));
console.log("[1,3,2]" + " -> " + almostIncreasingSequence([1,3,2]));
console.log("[1,3,2,4,5,6,8]" + " -> " + almostIncreasingSequence([1,3,2,4,5,6,8]));
console.log("[1,3,2,4,5,6,8,2]" + " -> " + almostIncreasingSequence([1,3,2,4,5,6,8,2]));
console.log(`[1,3,2,1] -> ${almostIncreasingSequence([1,3,2,1])}`);
console.log(`[1,3,2] -> " + ${almostIncreasingSequence([1,3,2])}`);
console.log(`[1,3,2,4,5,6,8] -> " + ${almostIncreasingSequence([1,3,2,4,5,6,8])}`);
console.log(`[1,3,2,4,5,6,8,2] -> " + ${almostIncreasingSequence([1,3,2,4,5,6,8,2])}`);