<commit_before>/*
Gradebook from Names and Scores

I worked on this challenge with: <NAME>
                                 <NAME>
This challenge took me [#] hours.

You will work with the following two variables.  The first, students, holds the names of four students.
The second, scores, holds groups of test scores.  The relative positions of elements within the two
variables match (i.e., 'Joseph' is the first element in students; his scores are the first value in scores.).

Do not alter the students and scores code.

*/

// var students = ["Joseph", "Susan", "William", "Elizabeth"]

// var scores = [ [80, 70, 70, 100],
//                [85, 80, 90, 90],
//                [75, 70, 80, 75],
//                [100, 90, 95, 85] ]

// // __________________________________________
// // Write your code below.

// // Make each student name in students a property of gradebook and assign each the value of a new object.
// var gradebook = {};

// for (var i = 0; i < students.length; i++) {
//   gradebook[students[i]] = {};
// }

// // Give each student property of gradebook its own testScores property and assign it the value of the respective students scores from scores.

// for (var i = 0; i < students.length; i++) {
//   //gradebook[students[i]].testScores = scores[i];
//  gradebook[students[i]] = { testScores: scores[i] };
// }

// // Assign an addScore property to gradebook. Give it the value of a function that accepts name and scorearguments.
// // Have addScore push the score to the value of the testScore property of the gradebook property that matches the value of the name argument.
// // gradebook[students name].testscores.push (new value)

// gradebook.addScore = function (name, score) {
//   this[name].testScores.push(score);
// }


// // Add the getAverage property to gradebook and assign it the value of a function. (This won't actually do anything just yet...)

// gradebook.getAverage = function(name) {
//   var scores = gradebook[name].testScores;
//   return average(scores);
// };

// // Create a new function average that accepts an array of integers and return the average of those integers.
// // NOTE: getAverage and average are different functions.

// var average = function(arr){
//   var summ = 0;
//   for (var j = 0; j < arr.length; j++){
//     summ += arr[j];
//   }
//   return summ / arr.length;
// };



// __________________________________________
// Refactored Solution

var students = ["Joseph", "Susan", "William", "Elizabeth"]

var scores = [ [80, 70, 70, 100],
               [85, 80, 90, 90],
               [75, 70, 80, 75],
               [100, 90, 95, 85] ]

var gradebook = {};

for (var i in students) {
  gradebook[students[i]] = {};
}

for (var i in students) {
  gradebook[students[i]].testScores = scores[i];
}

gradebook.addScore = function (name, score) {
  this[name].testScores.push(score);
}

gradebook.getAverage = function(name) {
  var scores = gradebook[name].testScores;
  return average(scores);
};

var average = function(arr){
  var summ = 0;
  for (var j in arr){
    summ += arr[j];
  }
  return summ / arr.length;
};

// __________________________________________
// Reflect
/*
What did you learn about adding functions to objects?
How did you iterate over nested arrays in JavaScript?
Were there any new methods you were able to incorporate? If so, what were they and how did they work?





*/
// __________________________________________
// Test Code:  Do not alter code below this line.

<commit_msg>complete 8.2 challenge<commit_after>/*
Gradebook from Names and Scores

I worked on this challenge with: <NAME>
                                 
This challenge took me 2 hours.

You will work with the following two variables.  The first, students, holds the names of four students.
The second, scores, holds groups of test scores.  The relative positions of elements within the two
variables match (i.e., 'Joseph' is the first element in students; his scores are the first value in scores.).

Do not alter the students and scores code.

*/

// var students = ["Joseph", "Susan", "William", "Elizabeth"]

// var scores = [ [80, 70, 70, 100],
//                [85, 80, 90, 90],
//                [75, 70, 80, 75],
//                [100, 90, 95, 85] ]

// // __________________________________________
// // Write your code below.

// // Make each student name in students a property of gradebook and assign each the value of a new object.
// var gradebook = {};

// for (var i = 0; i < students.length; i++) {
//   gradebook[students[i]] = {};
// }

// // Give each student property of gradebook its own testScores property and assign it the value of the respective students scores from scores.

// for (var i = 0; i < students.length; i++) {
//   //gradebook[students[i]].testScores = scores[i];
//  gradebook[students[i]] = { testScores: scores[i] };
// }

// // Assign an addScore property to gradebook. Give it the value of a function that accepts name and scorearguments.
// // Have addScore push the score to the value of the testScore property of the gradebook property that matches the value of the name argument.
// // gradebook[students name].testscores.push (new value)

// gradebook.addScore = function (name, score) {
//   this[name].testScores.push(score);
// }


// // Add the getAverage property to gradebook and assign it the value of a function. (This won't actually do anything just yet...)

// gradebook.getAverage = function(name) {
//   var scores = gradebook[name].testScores;
//   return average(scores);
// };

// // Create a new function average that accepts an array of integers and return the average of those integers.
// // NOTE: getAverage and average are different functions.

// var average = function(arr){
//   var summ = 0;
//   for (var j = 0; j < arr.length; j++){
//     summ += arr[j];
//   }
//   return summ / arr.length;
// };



// __________________________________________
// Refactored Solution

var students = ["Joseph", "Susan", "William", "Elizabeth"]

var scores = [ [80, 70, 70, 100],
               [85, 80, 90, 90],
               [75, 70, 80, 75],
               [100, 90, 95, 85] ]

var gradebook = {};

for (var i in students) {
  gradebook[students[i]] = {};
}

for (var i in students) {
  gradebook[students[i]].testScores = scores[i];
}

gradebook.addScore = function (name, score) {
  this[name].testScores.push(score);
}

gradebook.getAverage = function(name) {
  var scores = gradebook[name].testScores;
  return average(scores);
};

var average = function(arr){
  var summ = 0;
  for (var j in arr){
    summ += arr[j];
  }
  return summ / arr.length;
};

// __________________________________________
// Reflect
/*
What did you learn about adding functions to objects?

> The proper syntax. In JavaScript, a function is an attribute of an object and it is simple to add one.

How did you iterate over nested arrays in JavaScript?

> Using a simple for loop

Were there any new methods you were able to incorporate? If so, what were they and how did they work?

> No, not this time.
*/
// __________________________________________
// Test Code:  Do not alter code below this line.


{'fraction_non_alphanumeric': 0.124597508049839, 'fraction_numerical': 0.020859582808343834, 'mean_word_length': 2.9188151398793196, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2839660', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2023, 'n_words': 847}