复制代码代码如下:
/******************************************* ***
*Createby:Joe Zhou
*説明:数组统计函数
******************************************** **/
$ .extend({
max:function(arr){
return cacl(arr、function(item、max){
if(!(max> item)){
返品アイテム。
}
それ以外 {
MAXを返します。
}
});
}、
min:function(arr){
return cacl(arr、function(item、min){
if(!(min <item)){
返品アイテム。
}
それ以外 {
Minを返します。
}
});
}、
合計:function(arr){
return cacl(arr、function(item、sum){
if(typeof(sum)== 'undefined'){
返品アイテム。
}
それ以外 {
return sum += item;
}
});
}、
AVG:function(arr){
if(typeof(arr)== 'undefined' || arr.length == 0){
0を返します。
}
this.sum(arr) / arr.lengthを返します。
}
});
$ .fn.extend({
max:function(){
$ .max(this.get());
}、
min:function(){
$ .min(this.get())を返します。
}、
合計:function(){
$ $ .sum(this.get());
}、
AVG:function(){
$ .avg(this.get());
}
});
function cacl(arr、callback){
var ret;
for(var i = 0; i <arr.length; i ++){
ret = callback(arr [i]、ret);
}
Retを返します。
}
array.prototype.max = function(){
cacl(this、function(item、max)を返す{
if(!(max> item)){
返品アイテム。
}
それ以外 {
MAXを返します。
}
});
};
array.prototype.min = function(){
cacl(this、function(item、min){
if(!(min <item)){
返品アイテム。
}
それ以外 {
Minを返します。
}
});
};
array.prototype.sum = function(){
return cacl(this、function(item、sum){
if(typeof(sum)== 'undefined'){
返品アイテム。
}
それ以外 {
return sum += item;
}
});
};
array.prototype.avg = function(){
if(this.length == 0){
0を返します。
}
this.sum(this) / this.lengthを返します。
};