/
arrays.js
60 lines (52 loc) · 1.14 KB
/
arrays.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// arrays.js - part of the fq engine
// (c)2000-2002 Cal Henderson and Elliot Brady
//
// Array extensions
//
//
// array.shift removes the first element of an array and returns it
//
if (typeof(Array.shift) == 'undefined'){
Array.prototype.shift = function ArrayShift(){
var first = this[0];
for (var i=0; i<this.length-1; i++){
this[i] = this[i+1];
}
this.length--;
return first;
};
}
//
// array.push adds an element to the end of the array
//
if (typeof(Array.push) == 'undefined'){
Array.prototype.push = function ArrayPush(){
for (var i=0; i <arguments.length; i++){
this[this.length] = arguments[i];
}
};
}
//
// array.remove removes an indexed element of an array and returns it
//
if (typeof(Array.remove) == 'undefined'){
Array.prototype.remove = function ArrayRemove(a){
var item = this[a];
for (var i=a; i<this.length-1; i++){
this[i] = this[i+1];
}
this.length--;
return item;
};
}
//
// array.pop removes an element from the end of the array
//
if (typeof(Array.pop) == 'undefined'){
Array.prototype.pop = function ArrayPop(){
var result = this[this.length-1];
this.length--;
return result;
};
}