Sha256: da76459f2b76c2595c67dfd358aaf8607fa03ad929b71e7619ecb887ecf4a8f7
Contents?: true
Size: 1.23 KB
Versions: 8
Compression:
Stored size: 1.23 KB
Contents
/** * Filters out all duplicate items from an array by checking the specified key * @param [key] {string} the name of the attribute of each object to compare for uniqueness if the key is empty, the entire object will be compared if the key === false then no filtering will be performed * @return {array} */ angular.module('ui.filters').filter('unique', function () { return function (items, filterOn) { if (filterOn === false) { return items; } if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { var hashCheck = {}, newItems = []; var extractValueToCompare = function (item) { if (angular.isObject(item) && angular.isString(filterOn)) { return item[filterOn]; } else { return item; } }; angular.forEach(items, function (item) { var valueToCheck, isDuplicate = false; for (var i = 0; i < newItems.length; i++) { if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { isDuplicate = true; break; } } if (!isDuplicate) { newItems.push(item); } }); items = newItems; } return items; }; });
Version data entries
8 entries across 8 versions & 1 rubygems