回答編集履歴
4
修正
test
CHANGED
@@ -19,3 +19,27 @@
|
|
19
19
|
console.log(list);
|
20
20
|
|
21
21
|
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
追記
|
26
|
+
|
27
|
+
すみません、-Infinityから-Infinityを引くとNaNになっちゃいますね…
|
28
|
+
|
29
|
+
やはり
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
|
33
|
+
var comp = function(a, b) {
|
34
|
+
|
35
|
+
if (a[1] === "") return 1;
|
36
|
+
|
37
|
+
if (b[1] === "") return -1;
|
38
|
+
|
39
|
+
return (b[1] - a[1]);
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
が妥当でしょうか
|
3
修正
test
CHANGED
@@ -14,10 +14,8 @@
|
|
14
14
|
|
15
15
|
}
|
16
16
|
|
17
|
-
|
18
|
-
|
19
17
|
var list = [["aaa",100],["bbb",10],["ccc",""],["ddd",30],["eee",40]].sort(comp);
|
20
18
|
|
21
|
-
|
19
|
+
console.log(list);
|
22
20
|
|
23
21
|
```
|
2
修正
test
CHANGED
@@ -18,4 +18,6 @@
|
|
18
18
|
|
19
19
|
var list = [["aaa",100],["bbb",10],["ccc",""],["ddd",30],["eee",40]].sort(comp);
|
20
20
|
|
21
|
+
|
22
|
+
|
21
23
|
```
|
1
修正
test
CHANGED
@@ -4,20 +4,18 @@
|
|
4
4
|
|
5
5
|
```javascript
|
6
6
|
|
7
|
-
function
|
7
|
+
var comp = function(a, b) {
|
8
8
|
|
9
|
-
|
9
|
+
var _a = (a[1] === "") ? -Infinity : a[1];
|
10
10
|
|
11
|
-
|
11
|
+
var _b = (b[1] === "") ? -Infinity : b[1];
|
12
12
|
|
13
|
-
var _b = (b[1] === "") ? -Infinity : b[1];
|
14
|
-
|
15
|
-
|
13
|
+
return (_b - _a);
|
16
|
-
|
17
|
-
});
|
18
|
-
|
19
|
-
return list;
|
20
14
|
|
21
15
|
}
|
22
16
|
|
17
|
+
|
18
|
+
|
19
|
+
var list = [["aaa",100],["bbb",10],["ccc",""],["ddd",30],["eee",40]].sort(comp);
|
20
|
+
|
23
21
|
```
|