-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.js
More file actions
63 lines (59 loc) · 1.46 KB
/
Copy pathArrays.js
File metadata and controls
63 lines (59 loc) · 1.46 KB
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
61
62
63
import ArrayList from './ArrayList'
/**
* @see http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html
*
* @constructor
* @private
*/
export default function Arrays() {};
/**
*/
Arrays.sort = function() {
var a = arguments[0], i, t, comparator, compare;
if (arguments.length === 1) {
compare = function(a, b) {
return a.compareTo(b);
}
a.sort(compare);
return;
} else if (arguments.length === 2) {
comparator = arguments[1];
compare = function(a, b) {
return comparator['compare'](a, b);
};
a.sort(compare);
} else if (arguments.length === 3) {
t = a.slice(arguments[1], arguments[2]);
t.sort();
var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
a.splice(0, a.length);
for (i = 0; i < r.length; i++) {
a.push(r[i]);
}
return;
} else if (arguments.length === 4) {
t = a.slice(arguments[1], arguments[2]);
comparator = arguments[3];
compare = function(a, b) {
return comparator['compare'](a, b);
};
t.sort(compare);
r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
a.splice(0, a.length);
for (i = 0; i < r.length; i++) {
a.push(r[i]);
}
return;
}
};
/**
* @param {Array} array
* @return {ArrayList}
*/
Arrays.asList = function(array) {
var arrayList = new ArrayList();
for (var i = 0, len = array.length; i < len; i++) {
arrayList.add(array[i]);
}
return arrayList;
};