Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

almostincreasingsequence js

function almostIncreasingSequence(sequence) {
  let invalidItemsCount = 0;
  
  for (let i = 1; i < sequence.length; i++) {
    if (sequence[i] <= sequence[i-1]) {
      invalidItemsCount++;
      if (invalidItemsCount > 1) return false;
      if (sequence[i] <= sequence[i-2] && sequence[i+1] <= sequence[i-1]) return false;
    }
  }
  
  return true;
}

var test1 = [0,1,2,3,4,7,6,7,8,9,10];
var test2 = [0,1,2,4,3,4,5,7,6,7,8,9,10];

console.log(almostIncreasingSequence(test1));
console.log(almostIncreasingSequence(test2));
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: set radio button checked jquery 
Javascript :: socket io emit from socket instance or server 
Javascript :: character to ascii in js 
Javascript :: get window resolution javascript 
Javascript :: data-widget="pushmenu" collable automatically 
Javascript :: delete package-lock.json command 
Javascript :: javascript random alphabet 
Javascript :: datetimepicker set value 
Javascript :: how to remove first element of array javascript 
Javascript :: email validation regex 
Javascript :: Swap values with array destructuring 
Javascript :: js sentence to array 
Javascript :: get uploaded file name in js 
Javascript :: How to get unix timestamp from tomorrow nodejs 
Javascript :: how to get utc time in angular 
Javascript :: jquery trim 
Javascript :: how to remove duplicates from array in javascript 
Javascript :: this.$router.push nuxt 
Javascript :: open google chrome in puppeteer macos 
Javascript :: check if json obj exists 
Javascript :: new date with date + 1 
Javascript :: how to get data from ipfs 
Javascript :: big numbers factorial js 
Javascript :: get json by id 
Javascript :: how select start from id in jquery 
Javascript :: jquery toggle checkbox 
Javascript :: nuxt window is not defined 
Javascript :: javascript escape quote method 
Javascript :: adonis count with where 
Javascript :: js redirect page 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =