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

Function findNextLevel

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

Source from the content-addressed store, hash-verified

1015}
1016
1017const findNextLevel = function (levels, currentIndex, needsPractice) {
1018 let index = currentIndex + 1
1019 if (isAnyPrecedingLevelLocked(levels, currentIndex)) { return -1 }
1020 if (needsPractice) {
1021 if (isPractice(levels[currentIndex]) || ((index < levels.length) && isPractice(levels[index]))) {
1022 while ((index < levels.length) && (isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) {
1023 if (isLocked(levels[index])) { return -1 }
1024 index++
1025 }
1026 } else {
1027 index = findFirstIncompleteLevelOfPreviousPracticeChain(levels, currentIndex)
1028
1029 if (index === -1) {
1030 index = currentIndex + 1
1031 while ((index < levels.length) && (isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) {
1032 if (isLocked(levels[index])) { return -1 }
1033 index++
1034 }
1035 }
1036 }
1037 } else {
1038 while ((index < levels.length) && (isPractice(levels[index]) || isCompleteOrAssessmentOrSkipped(levels[index]) || isLocked(levels[index]))) {
1039 if (isLocked(levels[index])) { return -1 }
1040 index++
1041 }
1042 }
1043 return index
1044}
1045
1046// Practice level slugs are <mainLevelSlug>-[a-z]; the DB only stores locks on the parent level
1047// this works on junior only as they have practice levels related to parent level

Callers 1

determineNextLevelMethod · 0.85

Calls 5

isPracticeFunction · 0.85
isLockedFunction · 0.85

Tested by

no test coverage detected