Skip to content

Commit bc7d2c3

Browse files
committed
Update remove_duplicates.ts
1 parent d913e83 commit bc7d2c3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/format/remove_duplicates.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
export default function removeDuplicates<ArrayType extends string | number>(array : ArrayType[]) : ArrayType[] {
1+
/**
2+
* This function removes duplicates in an array. This function does not work for objects.
3+
*
4+
* @example
5+
* ```ts
6+
* console.log(removeDuplicates([1, 2, 3, 4, 3, 5, 4]));
7+
* // [1, 2, 3, 4, 5]
8+
*
9+
* console.log(removeDuplicates(['Apple', 'Banana', 'Banana', 'Cherry', 'Apple']));
10+
* // ['Apple', 'Banana', 'Cherry']
11+
* ```
12+
* @param array The array from where to remove duplicates from
13+
* @returns The array without duplicated items
14+
*/
15+
export default function removeDuplicates<
16+
ArrayType extends number | string | undefined
17+
>(array : ArrayType[]) : ArrayType[] {
218
return [...new Set(array)];
319
}

0 commit comments

Comments
 (0)