summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js b/js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js
new file mode 100644
index 0000000000..76285695db
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/sort/stability-5-elements.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2018 Mathias Bynens. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.prototype.sort
+description: >
+ Stability of Array.prototype.sort for an array with 5 elements.
+info: |
+ The sort is required to be stable (that is, elements that compare equal
+ remain in their original order).
+---*/
+
+const array = [
+ { name: 'A', rating: 2 },
+ { name: 'B', rating: 3 },
+ { name: 'C', rating: 2 },
+ { name: 'D', rating: 3 },
+ { name: 'E', rating: 3 },
+];
+assert.sameValue(array.length, 5);
+
+// Sort the elements by `rating` in descending order.
+// (This updates `array` in place.)
+array.sort((a, b) => b.rating - a.rating);
+
+const reduced = array.reduce((acc, element) => acc + element.name, '');
+assert.sameValue(reduced, 'BDEAC');
+
+reportCompare(0, 0);