MOBILE-3001 core: Improve performance of uniqueArray
parent
6dd8786da6
commit
a8037b80b7
|
@ -1258,18 +1258,16 @@ export class CoreUtilsProvider {
|
||||||
*/
|
*/
|
||||||
uniqueArray(array: any[], key?: string): any[] {
|
uniqueArray(array: any[], key?: string): any[] {
|
||||||
const filtered = [],
|
const filtered = [],
|
||||||
unique = [],
|
unique = {}; // Use an object to make it faster to check if it's duplicate.
|
||||||
len = array.length;
|
|
||||||
|
|
||||||
for (let i = 0; i < len; i++) {
|
array.forEach((entry) => {
|
||||||
const entry = array[i],
|
const value = key ? entry[key] : entry;
|
||||||
value = key ? entry[key] : entry;
|
|
||||||
|
|
||||||
if (unique.indexOf(value) == -1) {
|
if (!unique[value]) {
|
||||||
unique.push(value);
|
unique[value] = true;
|
||||||
filtered.push(entry);
|
filtered.push(entry);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue