A solution I consider more elegant:
const sum = times.reduce((a, b) => a + b, 0);
const avg = (sum / times.length) || 0;
console.log(`The sum is: ${sum}. The average is: ${avg}.`);
More Related Contents:
- Does an array contain a specific item? [duplicate]
- How to get the difference between two arrays of objects in JavaScript
- JavaScript: Difference between .forEach() and .map()
- How to extend an existing JavaScript array with another array, without creating a new array
- How to delete an item from state array?
- Maximum size of an Array in Javascript
- Create an array with same element repeated multiple times
- Merge JavaScript objects in array with same key
- How can I split a string into segments of n characters?
- adding custom functions into Array.prototype
- JavaScript – get array element fulfilling a condition
- Add a property to a JavaScript array
- Javascript – remove an array item by value [duplicate]
- Sorting on a custom order
- Index an array of arrays with an array of indexes in javascript
- How to free up the memory in JavaScript
- Javascript: take every nth Element of Array
- Trying to capitalize the first character in array of strings, why this is not working?
- How do I extract even elements of an Array?
- How to store a byte array in Javascript
- spread operator vs array.concat()
- Replace element at specific position in an array without mutating it
- push() a two-dimensional array
- Sort a Javascript Array by frequency and then filter repeats
- Javascript array search and remove string?
- TypeScript enum to object array
- Using lodash to compare jagged arrays (items existence without order)
- Using jQuery inArray with array of JavaScript Objects
- best way to generate empty 2D array
- Access object property in array of objects