Google News
logo
Collect.js - Interview Questions
What is average() method in Collect.js?
The average() method is used to return the average of all the items in a collection. This method is an alias of avg() method.
 
Syntax :
collect(array).average()
Parameters : The collect() method takes one argument that is converted into the collection and then average() function is applied on it, which can take element if you apply it on the collection of objects.

Example : 
const collect = require('collect.js');
  
let arr = [10, 20, 30];
  
let average = collect(arr).average();
  
console.log("Average of the given array: ", average);
Output:
Average of the given array:  20
Advertisement