@ce1pers/array-helpers
Version:
Included simple array helpers.
22 lines (21 loc) • 598 B
JavaScript
;
// @ts-check
Object.defineProperty(exports, "__esModule", { value: true });
exports.distincter = void 0;
/**
* Remove duplicate item in array.
*
* @throws {TypeError} Throws an type error if the 'array' argument is not array type.
*/
const distincter = (array) => {
try {
if (!Array.isArray(array))
throw new TypeError(`'array' argument must be 'array' type.`);
return Array.from(new Set(JSON.parse(JSON.stringify(array))));
}
catch (err) {
console.warn(err.message);
return array;
}
};
exports.distincter = distincter;