Skip to content

Commit

Permalink
remove util function and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Hussein committed Jul 4, 2024
1 parent a6c3f43 commit 7e82200
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
28 changes: 0 additions & 28 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,3 @@ export const removeItemFromArray = <T>(itemToRemove: T, array: T[]): T[] =>
export const mergeTwoArraysUniquely = <T>(array1: T[], array2: T[]): T[] => {
return Array.from(new Set(array1.concat(array2)));
};

/**
* Return a unique array of objects with no duplicates based on an object property
*
* @param {any[]} array
* @param {string} property
* @returns {any[]}
*/
export const uniqueArrayByObjectProperty = (array: any[], property: string) => {
const seenProperties = new Set();
const seenValues = new Set();

return array.filter((item) => {
if (item && typeof item === 'object' && Object.prototype.hasOwnProperty.call(item, property)) {
if (seenProperties.has(item[property])) {
return false;
}
seenProperties.add(item[property]);
return true;
}

if (seenValues.has(item)) {
return false;
}
seenValues.add(item);
return true;
});
};
39 changes: 0 additions & 39 deletions src/utils/tests/array/uniqueArrayByObjectProperty.test.ts

This file was deleted.

0 comments on commit 7e82200

Please sign in to comment.