MCPcopy Create free account
hub / github.com/codecombat/codecombat / findNextAssessmentForLevel

Function findNextAssessmentForLevel

app/core/utils.js:1061–1085  ·  view source on GitHub ↗
(levels, currentIndex, needsPractice)

Source from the content-addressed store, hash-verified

1059}
1060
1061const findNextAssessmentForLevel = function (levels, currentIndex, needsPractice) {
1062 // Find assessment level immediately after current level (and its practice levels)
1063 // Only return assessment if it's the next level
1064 // Skip over practice levels unless practice neeeded
1065 // levels = [{practice: true/false, complete: true/false, assessment: true/false, locked: true/false}]
1066 // eg: l*,p,p,a*,a',l,...
1067 // given index l*, return index a*
1068 // given index a*, return index a'
1069 let index = currentIndex
1070 index++
1071 while (index < levels.length) {
1072 if (levels[index].practice) {
1073 if (needsPractice && !levels[index].complete) { return -1 }
1074 index++ // It's a practice level but do not need practice, keep looking
1075 } else if (levels[index].assessment) {
1076 if (levels[index].complete) { return -1 }
1077 return index
1078 } else if (levels[index].complete) { // It's completed, keep looking
1079 index++
1080 } else { // we got to a normal level; we didn't find an assessment for the given level.
1081 return -1
1082 }
1083 }
1084 return -1 // we got to the end of the list and found nothing
1085}
1086
1087const needsPractice = function (playtime, threshold) {
1088 if (playtime == null) { playtime = 0 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected