/ Published in: JavaScript
URL: http://evanhahn.com/?p=663
Basically, this creates a string expression of all of the array values added up (eg, 1+2+3) and then evaluates it with eval. Finally, it divides by the number of elements.
Expand |
Embed | Plain Text
var average = eval(arrayToAverage.join('+')) / arrayToAverage.length;
You need to login to post a comment.
