Skip to content

Commit

Permalink
Add a uniq method to remove string duplicates from array
Browse files Browse the repository at this point in the history
Close #40
  • Loading branch information
gentooboontoo committed Jul 9, 2015
1 parent b8afbeb commit 97861ed
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/quantities.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
* @returns {string[]} names of kinds of units
*/
Qty.getKinds = function() {
var knownKinds = Object.keys(KINDS).map(function(knownSignature) {
return uniq(Object.keys(KINDS).map(function(knownSignature) {
return KINDS[knownSignature];
}).sort().filter(function(kind, index, arr) {
if (kind === arr[index-1]) {
return false;
}
return true;
});
return knownKinds;
}));
};

/**
Expand Down Expand Up @@ -1684,6 +1678,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return value;
}

/**
* Returns unique strings from list
*
* @param {string[]} array of strings
*
*
* @returns {string[]} a new array of strings without duplicates
*/
function uniq(strings) {
var seen = {};
return strings.filter(function(item) {
return seen.hasOwnProperty(item) ? false : (seen[item] = true);
});
}

/**
* Tests if a value is a string
*
Expand Down

0 comments on commit 97861ed

Please sign in to comment.