Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. function solve(input) {
  2. let output = '';
  3. input = input.filter(function(e){return e });
  4. let examString = input[input.length - 1].trim();
  5. let examAvg = [];
  6. for (let i = 0; i < input.length - 1; i++) {
  7. let data = input[i].split(' ');
  8. data = data.filter(function (e) { return e });
  9. let name = data[0];
  10. let exam = data[1];
  11. let points = Number(data[2]);
  12. let bonuses = Number(data[3]);
  13. let examPoints = (points / 5) + bonuses;
  14. let grade = (((examPoints / 80) * 4) + 2).toFixed(2);
  15. let finalGrade = 0;
  16. if (grade > 6.00) {
  17. finalGrade = (6.00).toFixed(2);
  18. } else {
  19. finalGrade = (Math.round(grade * 100) / 100).toFixed(2);
  20. }
  21. if (points < 100) {
  22. output += name + ' failed at "' + exam + '"\n';
  23. // console.log(`${name} failed at "${exam}"`);
  24. } else {
  25. output += name + ': Exam - "' + exam + '"; Points - ' + examPoints + '; Grade - ' + finalGrade + '\n';
  26. //console.log(`${name}: Exam - "${exam}"; Points - ${examPoints}; Grade - ${finalGrade}`);
  27. }
  28. if (examString === exam) {
  29. examAvg.push(points);
  30. }
  31. }
  32. let sum = 0;
  33. for (let grade of examAvg) {
  34. sum += grade;
  35. }
  36. let average = (sum / examAvg.length);
  37.  
  38. output += '"' + examString + '" average points -> ' + parseFloat(average.toFixed(2)) + '\n';
  39. //console.log(`"${examString}" average points -> ${average}`);
  40. console.log(output);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement