Last active
August 6, 2021 21:03
-
-
Save nedgrady/6bba7584369ea267aa248669ee46d2a9 to your computer and use it in GitHub Desktop.
This file contains 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
function areSomeNumberOfConsecutiveItemsPresentInArray( | |
targetNumberOfConsecutiveItems: number, | |
array: unknown[] | |
) { | |
let numberOfConsecutiveFound = 1 | |
let previousItem: unknown = {} | |
for (const currentItem of array) { | |
if (currentItem && currentItem === previousItem) | |
numberOfConsecutiveFound++ | |
if (numberOfConsecutiveFound === targetNumberOfConsecutiveItems) | |
return currentItem | |
previousItem = currentItem | |
} | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment