fixed a bug in Array.unique(..) (lib/util.js)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-08-08 03:55:38 +03:00
parent db5e7083a7
commit b36716c1ad
3 changed files with 17 additions and 13 deletions

View File

@ -197,6 +197,7 @@ var SlideshowActions = actions.Actions({
length_limit: that.config['slideshow-interval-max-count'],
check: Date.str2ms,
unique: Date.str2ms,
normalize: function(e){ return e.trim() },
sort: function(a, b){
return Date.str2ms(a) - Date.str2ms(b) },
})

View File

@ -80,14 +80,16 @@ Array.prototype.toKeys = function(normalize){
// NOTE: normalize will slow things down...
Array.prototype.toMap = function(normalize){
return normalize ?
this.reduce(function(m, e, i){
m.set(normalize(e), i)
return m
}, new Map())
: this.reduce(function(m, e, i){
m.set(e, i)
return m
}, new Map()) }
this
.reduce(function(m, e, i){
m.set(normalize(e), i)
return m
}, new Map())
: this
.reduce(function(m, e, i){
m.set(e, i)
return m
}, new Map()) }
// Return an array with duplicate elements removed...
@ -97,7 +99,9 @@ Array.prototype.toMap = function(normalize){
// NOTE: for an array containing only strings use a much faster .uniqueStrings(..)
// NOTE: this may not work on IE...
Array.prototype.unique = function(normalize){
return new Array(...(new Set(normalize ? this.map(normalize) : this))) }
return normalize ?
[...new Map(this.map(function(e){ return [normalize(e), e] })).values()]
: [...(new Set(this))] }
// Compare two arrays...

View File

@ -616,9 +616,8 @@ function(data, options){
// // If a function this will be used to normalize the values before
// // uniqueness check is performed...
// //
// // NOTE: this (if a function) is different from normalize above
// // in that this will not store the normalized value, rather
// // just use it for uniqueness testing...
// // NOTE: if this is a function the value returned is only used
// // for uniqueness checking and will not be stored.
// unique: <bool> | function(value){ ... },
//
// // called when new item is added to list...
@ -810,7 +809,7 @@ function(list, options){
// account for '$' as key binding marker...
lst = lst.unique(function(e){ return e.replace(/\$/g, '') })
// unique normalized...
// unique filter...
} else if(options.unique instanceof Function){
lst = lst.unique(options.unique)
}