forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_sort2.js
More file actions
117 lines (100 loc) · 2.75 KB
/
array_sort2.js
File metadata and controls
117 lines (100 loc) · 2.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
//Array sort testing for Object type
var x = new Object();
x = [8,41, 25, 7];
x.foo = Array.prototype.sort;
WScript.Echo(x.foo(function(a,b){return a - b}));
y = [9, 8, 4, 10, 190, 12, 20];
y.foo = Array.prototype.sort;
WScript.Echo(y.foo());
// Test sort on generic object
var objs = {
"empty array": function () {
return [];
},
"array with one undefined": function () {
return [undefined];
},
"array with one null": function () {
var o = [0];
delete o[0];
return o;
},
"array with two undefined": function () {
return [undefined, undefined];
},
"array with multiple undefined": function () {
var o = [undefined,,undefined,undefined,,,,undefined];
return o;
},
"array with multiple null": function () {
var o = [7,,5,2,,,6];
for (var i = 0; i < o.length; i++) {
delete o[i];
}
return o;
},
"array with mixed undefined and null": function () {
var o = [undefined,1,,9,,3,8,undefined];
delete o[0];
return o;
},
"empty object": function () {
return {
length: 0
};
},
"object with one undefined": function () {
return {
0: undefined,
length: 1
};
},
"object with one missing": function () {
return {
length: 1
};
},
"object with undefined, missing": function () {
return {
0: undefined,
length: 2
};
},
"object with multiple undefined": function () {
return {
0: undefined,
3: undefined,
7: undefined,
8: undefined,
length: 10
};
},
"adhoc object": function () {
return {
0: 7,
2: 5,
3: 2,
6: 6,
length: 10
};
},
};
function getObj(name) {
var obj = objs[name]();
obj.sort = Array.prototype.sort;
obj.join = Array.prototype.join;
obj.toString = Array.prototype.toString;
return obj;
}
var echo = WScript.Echo;
echo();
for (var name in objs) {
echo("Test " + name);
echo(getObj(name).sort());
echo(getObj(name).sort(function(a,b){return b - a;}));
echo();
}