Skip to content

Commit 2ca2ccd

Browse files
author
Orie Chinedu
committed
(stretch - callback): Implement remove duplicate element in an array
1 parent 4c7794c commit 2ca2ccd

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,14 @@ function removeDuplicates(array, cb) {
8282
// removeDuplicates removes all duplicate values from the given array.
8383
// Pass the duplicate free array to the callback function.
8484
// Do not mutate the original array.
85+
const distinctArray = []
86+
array.forEach((item) => {
87+
if (!distinctArray.includes(item)) {
88+
distinctArray.push(item);
89+
}
90+
})
91+
return cb(distinctArray);
8592
}
93+
removeDuplicates([1,1,2,2,3,3], (distinct) => {
94+
console.log(distinct)
95+
})

0 commit comments

Comments
 (0)