Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function maxSequenceOfEqualElements(arr) {
- let bestSequence = [];
- for (let index = 0; index < arr.length; index++) {
- let element = arr[index];
- let currentSequence = [element];
- for (let i = index + 1; i < arr.length; i++) {
- let nextElement = arr[i];
- if (element === nextElement) {
- currentSequence.push(nextElement);
- index = i;
- } else {
- break;
- }
- }
- if (currentSequence.length > bestSequence.length) {
- bestSequence = currentSequence;
- }
- }
- console.log(bestSequence.join(' '))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement