/
extend.js
36 lines (33 loc) · 900 Bytes
/
extend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
function isArray(obj){
return obj.constructor.toString().indexOf("Array") != -1;
}
Array.prototype.deepIndexOf = function(el){
for (var i = 0; i < this.length; i++){
if (el === this[i]){
return i;
}else if (isArray(this[i]) && isArray(el)){
if (this[i].length === el.length){
var equal = true;
for (var j = 0; j < el.length; j++){
if (this[i][j] != el[j]){
equal = false;
break;
}
}
if (equal){
return i;
}
}
}
}
return -1;
}
String.prototype.capitalize = function(){
return this[0].toUpperCase() + this.substr(1);
}