Switch to array uniquing function that keeps the first instance
The previous version would keep only the last instance. This version requires the array to contain only primitives of a single data type, but I think that's OK for all of our uses. (This version should also be faster.)
This commit is contained in:
parent
42c02526ef
commit
d65ee27592
1 changed files with 6 additions and 10 deletions
|
@ -604,23 +604,19 @@ Zotero.Utilities = {
|
|||
/**
|
||||
* Return new array with duplicate values removed
|
||||
*
|
||||
* From the JSLab Standard Library (JSL)
|
||||
* Copyright 2007 - 2009 Tavs Dokkedahl
|
||||
* Contact: http://www.jslab.dk/contact.php
|
||||
* From http://stackoverflow.com/a/1961068
|
||||
*
|
||||
* @param {Array} array
|
||||
* @return {Array}
|
||||
*/
|
||||
"arrayUnique":function(arr) {
|
||||
var a = [];
|
||||
var l = arr.length;
|
||||
for(var i=0; i<l; i++) {
|
||||
for(var j=i+1; j<l; j++) {
|
||||
// If this[i] is found later in the array
|
||||
if (arr[i] === arr[j])
|
||||
j = ++i;
|
||||
var u = {}, a = [];
|
||||
for (var i=0, l=arr.length; i<l; ++i){
|
||||
if (u.hasOwnProperty(arr[i])) {
|
||||
continue;
|
||||
}
|
||||
a.push(arr[i]);
|
||||
u[arr[i]] = 1;
|
||||
}
|
||||
return a;
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue