summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/core/utils.js')
-rw-r--r--addons/web/static/src/js/core/utils.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js
index ac9310dce90..acf8ca4d68d 100644
--- a/addons/web/static/src/js/core/utils.js
+++ b/addons/web/static/src/js/core/utils.js
@@ -349,6 +349,23 @@ var utils = {
].join(';');
},
/**
+ * Sort an array in place, keeping the initial order for identical values.
+ *
+ * @param {Array} array
+ * @param {function} iteratee
+ */
+ stableSort: function (array, iteratee) {
+ var stable = array.slice();
+ return array.sort(function stableCompare (a, b) {
+ var order = iteratee(a, b);
+ if (order !== 0) {
+ return order;
+ } else {
+ return stable.indexOf(a) - stable.indexOf(b);
+ }
+ });
+ },
+ /**
* @param {any} array
* @param {any} elem1
* @param {any} elem2