/** * Removes duplicated values within an array. * Supports numbers, strings and objects. */ export function removeDuplicates(array: T[], by = JSON.stringify): T[] { const seen: Record = {} return array.filter(item => { const key = by(item) return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true) }) }