Skip to content

Commit f880f1f

Browse files
authored
Make code example more realistic and safe
1. Without a real sorting part, the data output is not the same as with real sort (as the array is not really sorted when the callback returns `undefined`). 2. Current example may somehow encourage a reader to write sorting callbacks with undetermined behavior.
1 parent bdb3def commit f880f1f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

1-js/05-data-types/05-array-methods/article.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ By the way, if we ever want to know which elements are compared -- nothing preve
426426
```js run
427427
[1, -2, 15, 2, 0, 8].sort(function(a, b) {
428428
alert( a + " <> " + b );
429+
return a - b;
429430
});
430431
```
431432

0 commit comments

Comments
 (0)