var optionA = new option (scoreOptionA, weighting);
var optionB = new option (scoreOptionB, weighting);
var optionC = new option (scoreOptionC, weighting);
// imagine average() called as part of the output
console.log(optionA.toString());
console.log(optionB.toString());
console.log(optionC.toString());
// here, client code has to do all the work.
// imagine how many different ways it could be written
// and the potential for errors. Note the code will
// blow up when the array is empty; a simple edge case that
// would have been accounted for if a "coherent" (google that)
// sections object was created and debugged.
var sum, average = 0;
var options = [];
options.push(optionA, optionB, optionC);
options.forEach(option => {sum += option.score});
average = sum / options.length;
console.log("Average: ${average}");
// Calculating average usingwithin ana `options`sections object,
// Comprehension improvement is obvious when
// operation details are wrapped in the object's functions
var sections = new options();
sections.push(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");