Skip to content

Commit eb74897

Browse files
committed
Implement dedupe function to remove duplicate elements from an array
1 parent fa5733b commit eb74897

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎Sprint-1/implement/dedupe.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
function dedupe() {}
1+
function dedupe(elements) {
2+
if (elements.length === 0) {
3+
return [];
4+
}
5+
let newArray = [];
6+
for (const items of elements) {
7+
if (!newArray.includes(items)) {
8+
newArray.push(items);
9+
}
10+
}
11+
return newArray;
12+
}
13+
14+
module.exports = dedupe;

0 commit comments

Comments
 (0)