Last active
August 29, 2015 14:07
-
-
Save pedronauck/000483a8eefceddcaa1b to your computer and use it in GitHub Desktop.
Example of matrix manipulate with ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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