Last active
June 4, 2018 21:54
-
-
Save uzorjchibuzor/e6c7204ae35dc7dc2e68f6d78183e7b4 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 highestStreakInAnArray(result) { | |
let highStreak = 1, | |
currStreak = 1; | |
} | |
for (let i = 0; i < result.length; i++) { | |
if (result[i] === result[i + 1]) { | |
currStreak++; | |
if (currStreak > highStreak) { | |
highStreak = currStreak; | |
} | |
} else { | |
currStreak = 1; | |
} | |
} | |
return highStreak; | |
} |
for of loop is only good on objects!! for your request on material to study for objects, check JavaScript Info on Objects
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, Sorry for my late response!!! Your code works well and look simple and the performance is fine (initial run was around 7ms and normal run was 3.29ms) with the for loop. However we could make it more declarative. I will send my code soon.