From 71aa4033a4f7a6eb0f9f3c23a2e995963ad28f0c Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Mon, 29 May 2017 14:59:06 +0200 Subject: [PATCH] Add numeric sorting --- src/core/operations/SeqUtils.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/core/operations/SeqUtils.js b/src/core/operations/SeqUtils.js index 96fae0aa..351b0afe 100755 --- a/src/core/operations/SeqUtils.js +++ b/src/core/operations/SeqUtils.js @@ -26,7 +26,7 @@ const SeqUtils = { * @constant * @default */ - SORT_ORDER: ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address"], + SORT_ORDER: ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address", "Numeric"], /** * Sort operation. @@ -47,6 +47,8 @@ const SeqUtils = { sorted = sorted.sort(SeqUtils._caseInsensitiveSort); } else if (order === "IP address") { sorted = sorted.sort(SeqUtils._ipSort); + } else if (order === "Numeric") { + sorted = sorted.sort(SeqUtils._numericSort); } if (sortReverse) sorted.reverse(); @@ -221,6 +223,33 @@ const SeqUtils = { return a_ - b_; }, + /** + * Comparison operation for sorting of numeric values. + * + * @private + * @param {string} a + * @param {string} b + * @returns {number} + */ + _numericSort: function _numericSort(a, b) { + let a_ = a.split(/([^\d]+)/), + b_ = b.split(/([^\d]+)/); + + for (let i=0; i