Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function maxSequence(arr){
- indexOfContent = -1;
- maxLength = 0;
- for(let i = 0; i < arr.length;i++){
- let currentCountent = arr[i];
- let currentLength = 1;
- for(let j = i + 1;j < arr.length;j++){
- let nextCountent = arr[j];
- if(currentCountent !== nextCountent){
- break;
- }
- currentLength++;
- }
- if(currentLength > maxLength){
- maxLength = currentLength;
- indexOfContent = i;
- }
- }
- let element = arr[indexOfContent];
- console.log(`${element} `.repeat(maxLength));
- }
- maxSequence([2,1,1,2,3,3,2,2,2,1]);
Advertisement
Add Comment
Please, Sign In to add comment