Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- var examPoints,
- coursePoints,
- bonusPoints,
- name,
- course,
- grade;
- var avgCourse = [arr[arr.length -1].trim(), 0, 0];
- for (var i = 0; i < arr.length - 1; i++) {
- var obj = arr[i].trim().split(' ').filter(function (x) {
- return x;
- });
- name = obj[0];
- course = obj[1];
- examPoints = Number(obj[2]);
- bonusPoints = Number(obj[3]);
- if (course === avgCourse[0]) {
- avgCourse[1] += examPoints;
- avgCourse[2]++;
- }
- if (examPoints < 100) {
- console.log('%s failed at "%s"', name, course);
- continue;
- }
- coursePoints = examPoints * 0.2 + bonusPoints;
- coursePoints = Math.round(coursePoints * 100)/100;
- grade = Math.min(((coursePoints / 80) * 4)+2, 6);
- grade = grade.toFixed(2);
- console.log('%s: Exam - "%s"; Points - %s; Grade - %s', name, course, coursePoints, grade);
- }
- console.log('"%s" average points -> %s', avgCourse[0], Math.round(avgCourse[1]/avgCourse[2] * 100)/100);
- }
- var arr = [ 'Pesho C#-Advanced 100 3',
- 'Gosho Java-Basics 157 3',
- 'Tosho HTML&CSS 317 12',
- 'Minka C#-Advanced 57 15',
- 'Stanka C#-Advanced 157 15',
- 'Kircho C#-Advanced 300 0',
- 'Niki C#-Advanced 400 10',
- 'C#-Advanced' ];
- solve(arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement