Posted By

EvanHahn on 03/17/12


numbers array average

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Average array

 / Published in: JavaScript


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.

  1. var average = eval(arrayToAverage.join('+')) / arrayToAverage.length;

Report this snippet  

You need to login to post a comment.