Advertisement
Spocoman

07. Max Sequence of Equal Elements

Jan 22nd, 2022 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let print = [];
  3.     for(let i = 0; i < arr.length; i++) {
  4.         let current = [];
  5.         for(let j = ++i; j < arr.length; j++) {
  6.             if (arr[i] === arr[j]){
  7.                 current.push(arr[i]);
  8.             } else {
  9.                 i = ++j;
  10.                 break;
  11.             }
  12.         }
  13.         current.length > print.length ? print = current : print;
  14.     }
  15.     console.log(print.join(" "));
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement