Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let maxUnsatisfyingGrades = Number(input[index++]);
- let unsatisfyingGrades = 0;
- let gradesSum = 0;
- let problemsCount = 0;
- let lastProblem = undefined;
- let currentProblem = input[index++];
- while(currentProblem !== "Enough") {
- let currentGrade = Number(input[index++]);
- if (currentGrade <= 4) {
- unsatisfyingGrades++;
- if(unsatisfyingGrades === maxUnsatisfyingGrades) {
- break;
- }
- }
- gradesSum += currentGrade;
- problemsCount++;
- lastProblem = currentProblem;
- if(unsatisfyingGrades === maxUnsatisfyingGrades) {
- console.log(`You need a break, ${maxUnsatisfyingGrades} poor grades.`);
- } else {
- console.log(`Average score: ${(gradesSum / problemsCount).toFixed(2)}`);
- console.log(`Numbers of problems: ${problemsCount}`);
- console.log(`Last problem: ${lastProblem}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment