Ivankooo1

Max Sequence of Equals Elements

Dec 17th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function maxSequence(arr){
  2.    indexOfContent = -1;
  3.    maxLength = 0;
  4.  
  5.    for(let i = 0; i < arr.length;i++){
  6.        let currentCountent = arr[i];
  7.        let currentLength = 1;
  8.  
  9.      for(let j = i + 1;j < arr.length;j++){
  10.        let nextCountent = arr[j];
  11.      
  12.        if(currentCountent !== nextCountent){
  13.           break;
  14.        }
  15.      currentLength++;
  16.      }
  17.  
  18.      if(currentLength > maxLength){
  19.          maxLength = currentLength;
  20.          indexOfContent = i;
  21.      }
  22.    }
  23.    let element = arr[indexOfContent];
  24.    console.log(`${element} `.repeat(maxLength));
  25. }
  26. maxSequence([2,1,1,2,3,3,2,2,2,1]);
Advertisement
Add Comment
Please, Sign In to add comment