From b5517eac85989eee256bc9622a0da00d00a73e74 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 23 Mar 2018 02:22:42 +0300 Subject: [PATCH] tweaking... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/core.js | 1 + ui (gen4)/lib/util.js | 34 ++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 264389ff..53fba97a 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -1475,6 +1475,7 @@ var ChangesActions = actions.Actions({ Mark item(s) of section as changed... .markChanged(
, [, .. ]) + NOTE: items must be strings... NOTE: when marking section items, the new items will be added to the set of already marked items. diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index 4ee0d991..a204c60c 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -55,26 +55,23 @@ Array.prototype.compact = function(){ // NOTE: this will forget repeating items... // NOTE: normalize will slow things down... Array.prototype.toKeys = function(normalize){ - return this.reduce(function(r, e, i){ - r[normalize ? normalize(e) : e] = i - return r - }, {}) + return normalize ? + this.reduce(function(r, e, i){ + r[normalize(e)] = i + return r + }, {}) + : this.reduce(function(r, e, i){ + r[e] = i + return r + }, {}) } -/* -Array.prototype.compact = function(){ - var res = [] - for(var i in res){ - res.push(this[i]) - } - return res -} -*/ // Return an array with duplicate elements removed... // // NOTE: we are not using an Object as an index here as an Array can // contain any type of item while Object keys can only be strings... +// NOTE: for an array containing only strings use a much faster .uniqueStrings(..) Array.prototype.unique = function(normalize){ if(normalize){ var cache = this.map(function(e){ return normalize(e) }) @@ -86,8 +83,9 @@ Array.prototype.unique = function(normalize){ } -// Special case of .unique, allot faster on arrays of strings... +// Special case of .unique(), allot faster on arrays of strings... // +// NOTE: this may jield unexpected results for non-string items... Array.prototype.uniqueStrings = function(normalize){ return Object.keys(this.toKeys(normalize)) } @@ -114,8 +112,12 @@ Array.prototype.cmp = function(other){ // This will ignore order Array.prototype.setCmp = function(other){ return this === other - || this.unique().sort().cmp(other.unique().sort()) -} + || this + .unique() + .sort() + .cmp(other + .unique() + .sort()) } var args2array =