mobility-toolbox-js
Version:
Toolbox for JavaScript applications in the domains of mobility and logistics.
25 lines (24 loc) • 859 B
JavaScript
/**
* This function remove duplicates lower case string value of an array.
* It removes also null, undefined or non string values.
*
* @param {array} array Array of values.
* @private
*/
function removeDuplicate(array) {
const arrWithoutEmptyValues = array.filter((val) => {
var _a;
return (_a = val === null || val === void 0 ? void 0 : val.trim) === null || _a === void 0 ? void 0 : _a.call(val);
});
const lowerCasesValues = arrWithoutEmptyValues.map((str) => {
return str.toLowerCase();
});
const uniqueLowerCaseValues = [...new Set(lowerCasesValues)];
const uniqueValues = uniqueLowerCaseValues.map((uniqueStr) => {
return arrWithoutEmptyValues.find((str) => {
return str.toLowerCase() === uniqueStr;
});
});
return uniqueValues;
}
export default removeDuplicate;