(
function
() {
if
(
typeof
Array.prototype.forEach !=
"function"
) {
Array.prototype.forEach =
function
(fn, context) {
for
(
var
i = 0; i <
this
.length; i++) {
if
(
typeof
fn ===
"function"
&& Object.prototype.hasOwnProperty.call(
this
, i)) {
fn.call(context,
this
[i], i,
this
);
}
}
};
}
if
(
typeof
Array.prototype.map !=
"function"
) {
Array.prototype.map =
function
(fn, context) {
var
arr = [];
if
(
typeof
fn ===
"function"
) {
for
(
var
k = 0, length =
this
.length; k < length; k++) {
arr.push(fn.call(context,
this
[k], k,
this
));
}
}
return
arr;
};
}
if
(
typeof
Array.prototype.filter !=
"function"
) {
Array.prototype.filter =
function
(fn, context) {
var
arr = [];
if
(
typeof
fn ===
"function"
) {
for
(
var
k = 0, length =
this
.length; k < length; k++) {
fn.call(context,
this
[k], k,
this
) && arr.push(
this
[k]);
}
}
return
arr;
};
}
if
(
typeof
Array.prototype.every !=
"function"
) {
Array.prototype.every =
function
(fn, context) {
var
passed =
true
;
if
(
typeof
fn ===
"function"
) {
for
(
var
k = 0, length =
this
.length; k < length; k++) {
if
(passed ===
false
)
break
;
passed = !!fn.call(context,
this
[k], k,
this
);
}
}
return
passed;
};
}
if
(
typeof
Array.prototype.some !=
"function"
) {
Array.prototype.some =
function
(fn, context) {
var
passed =
false
;
if
(
typeof
fn ===
"function"
) {
for
(
var
k = 0, length =
this
.length; k < length; k++) {
if
(passed ===
true
)
break
;
passed = !!fn.call(context,
this
[k], k,
this
);
}
}
return
passed;
};
}
if
(
typeof
Array.prototype.indexOf !=
"function"
) {
Array.prototype.indexOf =
function
(item, index) {
var
n =
this
.length,
i = index ==
null
? 0 : index < 0 ? Math.max(0, n + index) : index;
for
(; i < n; i++) {
if
(i
in
this
&&
this
[i] === item) {
return
i
}
}
return
-1
};
}
if
(
typeof
Array.prototype.lastIndexOf !=
"function"
) {
Array.prototype.lastIndexOf =
function
(item, index) {
var
n =
this
.length,
i = index ==
null
? n-1 : index < 0 ? Math.max(0, n + index) : index;
for
(; i >= 0; i--) {
if
(i
in
this
&&
this
[i] === item) {
return
i;
}
}
return
-1;
};
}
if
(
typeof
Array.prototype.reduce !=
"function"
) {
Array.prototype.reduce =
function
(callback, initialValue) {
var
previous = initialValue, k = 0, length =
this
.length;
if
(
typeof
initialValue ===
"undefined"
) {
previous =
this
[0];
k = 1;
}
if
(
typeof
callback ===
"function"
) {
for
(k; k < length; k++) {
this
.hasOwnProperty(k) && (previous = callback(previous,
this
[k], k,
this
));
}
}
return
previous;
};
}
if
(
typeof
Array.prototype.reduceRight !=
"function"
) {
Array.prototype.reduceRight =
function
(callback, initialValue) {
var
length =
this
.length, k = length - 1, previous = initialValue;
if
(
typeof
initialValue ===
"undefined"
) {
previous =
this
[length - 1];
k--;
}
if
(
typeof
callback ===
"function"
) {
for
(k; k > -1; k-=1) {
this
.hasOwnProperty(k) && (previous = callback(previous,
this
[k], k,
this
));
}
}
return
previous;
};
}
if
(
typeof
Array.prototype.uniq !=
"function"
) {
Array.prototype.uniq =
function
() {
var
arr = [];
arr[0] =
this
[0];
for
(
var
i = 1; i <
this
.length; i++) {
if
(arr.indexOf(
this
[i]) == -1) {
arr.push(
this
[i]);
}
}
return
arr;
};
}
if
(
typeof
Array.prototype.remove !=
"function"
) {
Array.prototype.remove =
function
(item) {
for
(
var
i =
this
.length; i >= 0; i--) {
if
(item ===
this
[i]) {
this
.splice(i, 1);
}
}
return
this
;
};
}
if
(
typeof
Array.prototype.shuffle !=
"function"
) {
Array.prototype.shuffle =
function
() {
var
i =
this
.length;
while
(i) {
var
j = Math.floor(Math.random()*i);
var
t =
this
[--i];
this
[i] =
this
[j];
this
[j] = t;
}
return
this
;
};
}
if
(
typeof
Array.prototype.max !=
"function"
) {
Array.prototype.max =
function
() {
return
Math.max.apply({},
this
)
};
}
if
(
typeof
Array.prototype.max !=
"function"
) {
Array.prototype.min =
function
() {
return
Math.min.apply({},
this
)
};
}
if
(
typeof
Array.prototype.isArray !=
"function"
) {
Array.prototype.isArray =
function
() {
return
Object.prototype.toString.apply(
this
) ===
"[object Array]"
;
};
}
}());