Skip to content

Instantly share code, notes, and snippets.

@uzorjchibuzor
Last active June 4, 2018 21:54
Show Gist options
  • Save uzorjchibuzor/e6c7204ae35dc7dc2e68f6d78183e7b4 to your computer and use it in GitHub Desktop.
Save uzorjchibuzor/e6c7204ae35dc7dc2e68f6d78183e7b4 to your computer and use it in GitHub Desktop.
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;
}
@uzorjchibuzor
Copy link
Author

uzorjchibuzor commented Jun 3, 2018

I want to use a reverse For loop to improve the performance index of the function, still working on it but if there is a way to use a For..of loop, I will be satisfied with that, performance or no.

@Oluwasetemi
Copy link

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.

@Oluwasetemi
Copy link

for of loop is only good on objects!! for your request on material to study for objects, check JavaScript Info on Objects

@Oluwasetemi
Copy link

fcc5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment