<commit_before>/*
Gradebook from Names and Scores
I worked on this challenge [by myself, with: John C]
This challenge took me [1] 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.

// var gradebook = {};
// gradebook[students[0]]={};
// gradebook[students[1]]={};
// gradebook[students[2]]={};
// gradebook[students[3]]={};

// var index = 0;
// for (var name in gradebook){
//   gradebook[name].testScores =[];
//   gradebook[name].testScores = scores[index];
//   index++;
// }


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

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

// function average(array){
//   var sum = 0;
//   array.forEach(function(element){
//     sum +=element;
//   });
//   return (sum/array.length);
// }


// __________________________________________
// Refactored Solution
var gradebook = {};
// gradebook[students[0]]={};
// gradebook[students[1]]={};
// gradebook[students[2]]={};
// gradebook[students[3]]={};
 
students.forEach(function(name){
  gradebook[name]={};
});

var index = 0;
for (var name in gradebook){
  gradebook[name].testScores =[];
  gradebook[name].testScores = scores[index];
  index++;
}

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

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

function average(array){
  var sum = 0;
  array.forEach(function(element){
    sum += element;
  });
  return (sum/array.length);
}

console.log(gradebook);







// __________________________________________
// Reflect









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

<commit_msg>update reflection for 8.2<commit_after>/*
Gradebook from Names and Scores
I worked on this challenge [by myself, with: John C]
This challenge took me [1] 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.

// var gradebook = {};
// gradebook[students[0]]={};
// gradebook[students[1]]={};
// gradebook[students[2]]={};
// gradebook[students[3]]={};

// var index = 0;
// for (var name in gradebook){
//   gradebook[name].testScores =[];
//   gradebook[name].testScores = scores[index];
//   index++;
// }


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

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

// function average(array){
//   var sum = 0;
//   array.forEach(function(element){
//     sum +=element;
//   });
//   return (sum/array.length);
// }


// __________________________________________
// Refactored Solution
var gradebook = {};
// gradebook[students[0]]={};
// gradebook[students[1]]={};
// gradebook[students[2]]={};
// gradebook[students[3]]={};
 
students.forEach(function(name){
  gradebook[name]={};
});

var index = 0;
for (var name in gradebook){
  gradebook[name].testScores =[];
  gradebook[name].testScores = scores[index];
  index++;
}

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

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

function average(array){
  var sum = 0;
  array.forEach(function(element){
    sum += element;
  });
  return (sum/array.length);
}

console.log(gradebook);







// __________________________________________
// Reflect

// What did you learn about adding functions to objects?

// - I had used functions in my objects for the game I made last week, but this was a good
// example of how to do it with arguments being passed.

// How did you iterate over nested arrays in JavaScript?
// -I did not really need to itterate in nested arrays for this challenge as the input was 
// only one level deep.  However, one could do this by calling a .forEach on every array within an array if needed.


// Were there any new methods you were able to incorporate? If so, what were they and how did they work?
// Using for... in... was helpful in initializing the gradebook testScores.  It was useful for iterating through
// an object.  

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


{'fraction_non_alphanumeric': 0.14691943127962084, 'fraction_numerical': 0.017499088589135983, 'mean_word_length': 3.603187919463087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6845507', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1604, 'n_words': 518}