Created
February 28, 2023 14:13
-
-
Save ChrisDobby/af6462abf3d9181ee5e98c189cf20534 to your computer and use it in GitHub Desktop.
Given a list of numbers, return all groups of repeating consecutive numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const repeatedGroups = (numbers: number[]) => | |
numbers | |
.reduce<number[][]>( | |
(acc, num) => (acc.length === 0 || !acc[acc.length - 1].includes(num) ? [...acc, [num]] : [...acc.slice(0, acc.length - 1), [...acc[acc.length - 1], num]]), | |
[] | |
) | |
.filter(nums => nums.length > 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment