[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.11448584 [View]
File: 6 KB, 294x204, avr.png [View same] [iqdb] [saucenao] [google]
11448584

>>11443948
Don't shit on JS if you don't know JS. Here's how to do it properly:

Array.prototype.avr = function() {
return (()=>{
let c = 0;
for (i=0;i<this.length;i++){
c+=this[i];
}
return c/this.length;
})();
}

const list = [1, 2, 3, 4, 5, 9, 10];
console.log(list.avr());

Although, you do have a point. Couldn't even use a lambda function as prototype for some reason, had to return an anonymous function for no reason. Anyone know why lambda functions aren't supported in prototypes?

Navigation
View posts[+24][+48][+96]