Every line of 'javascript math average' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
135 function average(values) { 136 let total = 0.0; 137 let count = 0; 138 139 values.forEach(v => { 140 if (missing(v)) { 141 return; 142 } 143 144 total += v; 145 count += 1; 146 }); 147 148 if (count === 0) { 149 return null; 150 } 151 152 return total / count; 153 }
772 function average(array) { 773 var sum = 0; 774 for (var i = 0; i < array.length; i++) { 775 sum += Math.round(array[i]); 776 } 777 return (sum / array.length); 778 }
73 function average(array) { 74 function plus(a, b) { 75 return a + b 76 } 77 78 return array.reduce(plus) / array.length 79 }
28 get average() { 29 if (this.v.length < this.minsize) return -1; 30 else return this.sum/this.v.length; 31 }
112 function average(array) { 113 if (array.length === 0) { 114 return 0; 115 } 116 return ( 117 array.reduce(function(s, v) { 118 return v + s; 119 }, 0) / array.length 120 ); 121 }
316 function average(data) { 317 var sum = data.reduce(function(sum, value) { 318 return sum + value; 319 }, 0); 320 321 var avg = sum / data.length; 322 return avg; 323 }
1064 function Average(obj) { 1065 var point = null; 1066 if (typeof obj == "function") { 1067 point = new AverageFuncPoint(obj); 1068 } else if (typeof obj == "string") { 1069 point = new AveragePropPoint(obj); 1070 } else { 1071 point = new AveragePoint(); 1072 } 1073 this.run(point); 1074 if (point.items == 0) return 0; 1075 return point.total / point.items; 1076 }
60 function average (arr) { 61 var sum = 0, j = 0; 62 for (var i = 0; i < arr.length; i++) { 63 sum += arr[i]; ++j; 64 } 65 return j ? sum / j : 0; 66 }
3 function average(list) { 4 if (!list.length) 5 return 0; 6 7 var sum = list.reduce(function(previous, current) { 8 return previous + current; 9 }); 10 return (sum / list.length).toFixed(0); 11 }
61 this.average = function average( column_name, conditions, callback ){ 62 var options = {} 63 , column_name = column_name || 'id' 64 , conditions = conditions || {}; 65 /* Reload the cache */ 66 if (conditions.force) force = ActiveSupport.clone(conditions.force); delete conditions.force; 67 if(typeof(column_name)=="function"){ 68 callback = column_name; 69 column_name = 'id'; 70 } 71 if(typeof(conditions)=="function"){ 72 callback = conditions; 73 conditions = {}; 74 } 75 options = { 76 from: this.to_s(), 77 select: "AVG("+ column_name +")", 78 conditions: conditions 79 } 80 if (this._extra_parameters) options.extras = this._extra_parameters; 81 var query = new Query().make_select(options); 82 this.exec(query.sql, query.values, function (error, data){ 83 return callback ? callback(error, data[0][options.select]) : data; 84 } ); 85 return this; 86 }