Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.avg = function() {
- var av = 0;
- var cnt = 0;
- var len = this.length;
- for (var i = 0; i < len; i++) {
- var e = +this[i];
- if(!e && this[i] !== 0 && this[i] !== '0') e--;
- if (this[i] == e) {av += e; cnt++;}
- }
- return av/cnt;
- }
- var ary = [5,8,2,4,11,7,3];
- var average = ary.avg();
Add Comment
Please, Sign In to add comment