Skip to content

Instantly share code, notes, and snippets.

@pedronauck
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedronauck/000483a8eefceddcaa1b to your computer and use it in GitHub Desktop.
Save pedronauck/000483a8eefceddcaa1b to your computer and use it in GitHub Desktop.
Example of matrix manipulate with ES6
/*
* Function that calculate the average of a number
*
* @param {Number} num
* @param {Number} divisor
* @return {Number} simple arithmetic average of num
*
*/
var calcAverage = (num, divisor) => (num / divisor).toFixed(2);
var grades = [[90, 85, 78],[85, 95, 94],[92, 83, 87]];
grades.forEach((row, i) => {
let total = row.reduce((total, num) => total += num);
let average = calcAverage(total, row.length);
console.log('Student ${i + 1} average: ${average}');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment