Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function trainTheTrainers(input) {
- let scoreNum = Number(input[0]);
- let presentation = input[1];
- let presentationCounter = 0;
- let totalAverage = 0;
- let index = 2;
- while (presentation !== 'Finish'){
- let grade = 0
- for (let i = 0; i < scoreNum; i++){
- grade += Number(input[index++]);
- }
- console.log(`${presentation} - ${(grade / scoreNum).toFixed(2)}.`);
- totalAverage += grade / scoreNum;
- presentation = input[index++];
- presentationCounter++;
- }
- console.log(`Student\'s final assessment is ${(totalAverage / presentationCounter).toFixed(2)}.`);
- }
- Решение със shift():
- function trainTheTrainers(input) {
- let scoreNum = Number(input.shift());
- let presentation = input.shift();
- let presentationCounter = 0;
- let totalAverage = 0;
- while (presentation !== 'Finish'){
- let grade = 0
- for (let i = 0; i < scoreNum; i++){
- grade += Number(input.shift());
- }
- console.log(`${presentation} - ${(grade / scoreNum).toFixed(2)}.`);
- totalAverage += grade / scoreNum;
- presentation = input.shift();
- presentationCounter++;
- }
- console.log(`Student\'s final assessment is ${(totalAverage / presentationCounter).toFixed(2)}.`);
- }
- РЕШЕНИЕ С FOR И SHIFT():
- function trainTheTrainers(input) {
- let scoreNum = Number(input.shift());
- let totalAverage = 0;
- for (let i = 0; i < Number.MAX_SAFE_INTEGER; i++) {
- let presentation = input.shift();
- if (presentation === 'Finish') {
- console.log(`Student\'s final assessment is ${(totalAverage / i).toFixed(2)}.`);
- break;
- }
- let grade = 0;
- for (let j = 0; j < scoreNum; j++) {
- grade += Number(input.shift());
- }
- console.log(`${presentation} - ${(grade / scoreNum).toFixed(2)}.`);
- totalAverage += grade / scoreNum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement