Advertisement
Guest User

Untitled

a guest
Jan 31st, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     var examPoints,
  3.         coursePoints,
  4.         bonusPoints,
  5.         name,
  6.         course,
  7.         grade;
  8.     var avgCourse = [arr[arr.length -1].trim(), 0, 0];
  9.     for (var i = 0; i < arr.length - 1; i++) {
  10.         var obj = arr[i].trim().split(' ').filter(function (x) {
  11.             return x;
  12.         });
  13.         name = obj[0];
  14.         course = obj[1];
  15.         examPoints = Number(obj[2]);
  16.         bonusPoints = Number(obj[3]);
  17.         if (course === avgCourse[0]) {
  18.             avgCourse[1] += examPoints;
  19.             avgCourse[2]++;
  20.         }
  21.         if (examPoints < 100) {
  22.             console.log('%s failed at "%s"', name, course);
  23.             continue;
  24.         }
  25.         coursePoints = examPoints * 0.2 + bonusPoints;
  26.         coursePoints = Math.round(coursePoints * 100)/100;
  27.         grade = Math.min(((coursePoints / 80) * 4)+2, 6);
  28.         grade = grade.toFixed(2);
  29.         console.log('%s: Exam - "%s"; Points - %s; Grade - %s', name, course, coursePoints, grade);
  30.  
  31.  
  32.     }
  33.     console.log('"%s" average points -> %s', avgCourse[0], Math.round(avgCourse[1]/avgCourse[2] * 100)/100);
  34.  
  35. }
  36.  
  37. var arr = [ 'Pesho C#-Advanced 100 3',
  38.     'Gosho Java-Basics 157 3',
  39.     'Tosho HTML&CSS 317 12',
  40.     'Minka C#-Advanced 57 15',
  41.     'Stanka C#-Advanced 157 15',
  42.     'Kircho C#-Advanced 300 0',
  43.     'Niki C#-Advanced 400 10',
  44.     'C#-Advanced' ];
  45. solve(arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement