复制代码代码如下:
/***************************************************** ***
*Createby: Joe Zhou
*Descrição: 数组统计函数
**************************************************** **/
$ .Extend ({
max: function (arr) {
Retornar CACL (arr, função (item, max) {
if (! (max> item)) {
item de retorno;
}
outro {
retornar max;
}
});
},
min: function (arr) {
Retornar CACL (arr, function (item, min) {
if (! (min <item)) {
item de retorno;
}
outro {
retornar min;
}
});
},
Sum: function (arr) {
Retornar CACL (arr, função (item, soma) {
if (typeof (sum) == 'indefinido') {
item de retorno;
}
outro {
Retornar soma += item;
}
});
},
avg: function (arr) {
if (typeof (arr) == 'indefinido' || arr.length == 0) {
retornar 0;
}
retornar este.sum (arr) / arr.length;
}
});
$ .fn.extend ({
max: function () {
retornar $ .max (this.get ());
},
min: function () {
retornar $ .min (this.get ());
},
soma: function () {
retornar $ .sum (this.get ());
},
AVG: function () {
retornar $ .avg (this.get ());
}
});
função cacl (arr, retorno de chamada) {
var ret;
for (var i = 0; i <arn.length; i ++) {
ret = retorno de chamada (arr [i], ret);
}
retornar ret;
}
Array.prototype.max = function () {
Retornar CACL (isto, função (item, max) {
if (! (max> item)) {
item de retorno;
}
outro {
retornar max;
}
});
};
Array.prototype.min = function () {
Retornar CACL (isto, função (item, min) {
if (! (min <item)) {
item de retorno;
}
outro {
retornar min;
}
});
};
Array.prototype.sum = function () {
Retornar CACL (esta, função (item, soma) {
if (typeof (sum) == 'indefinido') {
item de retorno;
}
outro {
Retornar soma += item;
}
});
};
Array.prototype.avg = function () {
if (this.Length == 0) {
retornar 0;
}
retornar esta.sum (this) / this.length;
};