Created
May 13, 2019 23:24
-
-
Save trevorblades/08fc1a88270c41d49b92e13fdc48ae6c to your computer and use it in GitHub Desktop.
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
| export function getStreak(answers) { | |
| let streak = 0; | |
| for (const answer of answers) { | |
| if (!answer.correct) { | |
| break; | |
| } | |
| streak++; | |
| } | |
| // even if there are no answers, streak is still a number | |
| return streak; | |
| } |
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
| let value; | |
| this.props.options.forEach(option => { | |
| const path = this.props.useLink ? withPrefix(option.value) : option.value; | |
| const isActive = option.matchRegex | |
| ? option.matchRegex.test(path) | |
| : this.props.isPathActive(path); | |
| if (isActive) { | |
| value = option.value; | |
| } | |
| if (option.subpages) { | |
| option.subpages.forEach(subpage => { | |
| if (this.props.isPathActive(subpage.value)) { | |
| value = option.value; | |
| } | |
| }); | |
| } | |
| }); | |
| // use value down here and change the UI in some way if it's falsey (undefined) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment