From c5cbbb4f1d446a5f26bc4a610fc035df1affba12 Mon Sep 17 00:00:00 2001 From: "a. bellenir" Date: Wed, 20 Mar 2019 11:51:58 -0400 Subject: [PATCH] LP1821032 - compare_array implmenetation is confusing the existing implementation works but can much more concise. because it uses localeCompare, this suggested implementation will only work on arrays of strings. it can be modified to work on arrays of numbers too, if needed. Signed-off-by: a. bellenir --- .../web/js/ui/default/staff/cat/services/holdings.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/holdings.js b/Open-ILS/web/js/ui/default/staff/cat/services/holdings.js index d78c049bc3..ab2d681681 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/holdings.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/holdings.js @@ -90,22 +90,10 @@ function(egCore , $q) { svc.copies = svc.copies.sort( function (a, b) { function compare_array (x, y, i) { - if (x[i] && y[i]) { // both have values - if (x[i] == y[i]) { // need to look deeper - return compare_array(x, y, ++i); - } - - if (x[i] < y[i]) { // x is first - return -1; - } else if (x[i] > y[i]) { // y is first - return 1; - } - - } else { // no orgs to compare ... - if (x[i]) return -1; - if (y[i]) return 1; - } - return 0; + // the longer array "wins" if we run off the end of either: + if(i >= x.length || i >= y.length){ return y.length - x.length; } + // return a value if we find a difference, otherwise recurse: + return x[i].localeCompare(y[i]) || compare_array(x,y,i+1); } var owner_order = compare_array(a.owner_list, b.owner_list, 0); -- 2.11.0