Skip to content

Instantly share code, notes, and snippets.

@trevorblades
Created May 13, 2019 23:24
Show Gist options
  • Select an option

  • Save trevorblades/08fc1a88270c41d49b92e13fdc48ae6c to your computer and use it in GitHub Desktop.

Select an option

Save trevorblades/08fc1a88270c41d49b92e13fdc48ae6c to your computer and use it in GitHub Desktop.
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;
}
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