First, implement an internal function that filters out students who do not meet the cut off mark from listOfStudents
array. Then, call the internal function in the upgrade function:
+ function _checkPassedStudents() internal {
+ address[] memory newList = new address[](listOfStudents.length);
+ uint256 passingCount = 0;
+ for (uint256 i = 0; i < listOfStudents.length; i++) {
+ if (studentScore[listOfStudents[i]] >= cutOffScore) {
+ newList[passingCount] = listOfStudents[i];
+ passingCount++;
+ } else {
+ isStudent[listOfStudents[i]] = false;
+ reviewCount[listOfStudents[i]] = 0;
+ }
+ }
+ // 2. Resize and reassign the listOfStudents array
+ delete listOfStudents;
+ for (uint256 j = 0; j < passingCount; j++) {
+ listOfStudents.push(newList[j]);
+ }
+ }
function graduateAndUpgrade(
address _levelTwo,
bytes memory
) public onlyPrincipal {
if (_levelTwo == address(0)) {
revert HH__ZeroAddress();
}
// implement check for student that meets cut off mark
+ _checkPassedStudents();
uint256 totalTeachers = listOfTeachers.length;
uint256 payPerTeacher = (bursary * TEACHER_WAGE) / PRECISION;
uint256 principalPay = (bursary * PRINCIPAL_WAGE) / PRECISION;
_authorizeUpgrade(_levelTwo);
for (uint256 n = 0; n < totalTeachers; n++) {
usdc.safeTransfer(listOfTeachers[n], payPerTeacher);
}
usdc.safeTransfer(principal, principalPay);
}