Skip to content
Advertisement

Get the average of rates per assignment

I have the following data:

JavaScript

Now I need to calculate the average difficulty and fun rates per assignment. As you can see, not every student has the same assignments.

What approach is the best when starting blanco. .map()? Or better for (var i = 0; i < assignments.length; i++){//do something} methode?

I assume it is wise to first iterate over the assignments by students and iterate within that iterate over the rates.

Or is wiser to iterate over the persons first and within that iteration over the assignments and its rates for that person?

Advertisement

Answer

You could probably do some reduce magic but this what I find easier to read and understand for others coming across your code:

JavaScript
Advertisement