mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
back
This commit is contained in:
24
packages/cli/src/utils/array/index.test.ts
Normal file
24
packages/cli/src/utils/array/index.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { findDuplicates } from "@utils/array";
|
||||
|
||||
test("Find duplicates from array", () => {
|
||||
const testCases = [
|
||||
{
|
||||
input: [],
|
||||
output: [],
|
||||
},
|
||||
|
||||
{
|
||||
input: [1, 2, 3, 3, "3", "3"],
|
||||
output: [3, "3"],
|
||||
},
|
||||
{
|
||||
input: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
|
||||
output: [1, 2, 3, 4, 5],
|
||||
},
|
||||
];
|
||||
|
||||
testCases.forEach((testCase) => {
|
||||
const result = findDuplicates(testCase.input);
|
||||
expect(result).toEqual(testCase.output);
|
||||
});
|
||||
});
|
||||
5
packages/cli/src/utils/array/index.ts
Normal file
5
packages/cli/src/utils/array/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const findDuplicates = (arr: (string | number)[]) => {
|
||||
const duplicates = arr.filter((item, index) => arr.indexOf(item) !== index);
|
||||
const unique = new Set(duplicates);
|
||||
return Array.from(unique);
|
||||
};
|
||||
Reference in New Issue
Block a user