Last active
June 18, 2023 16:14
-
-
Save dsetzer/876d72e24679eac5738e429aa07f1021 to your computer and use it in GitHub Desktop.
Function to split up an array into separate groups of W/L streaks.
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
/** | |
* Takes in an array of numbers and returns an array of streaks of numbers. | |
* @param {Array} results - An array of numbers. | |
* @param {Number} multiplier - The number that determines the streak. | |
* @returns {Array} - An array of streaks of numbers. | |
*/ | |
function getStreaks(results, multiplier) { | |
let streaks = new Array(); | |
let streak = new Array(); | |
for (let i = 0; i < results.length; i++) { | |
if (results[i] >= multiplier) { | |
streak.push(results[i]); | |
} else { | |
if (streak.length > 0) { | |
streaks.push(streak); | |
streak = new Array(); | |
} | |
} | |
} | |
if (streak.length > 0) { | |
streaks.push(streak); | |
} | |
return streaks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment