Skip to content

Commit 0f08798

Browse files
callback stretch goals completed
1 parent c819b54 commit 0f08798

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎assignments/callbacks.js‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
1+
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum', "yo-yo"];
22

33
function firstItem(arr, cb) {
44
// firstItem passes the first item of the given array to the callback function.
@@ -75,4 +75,19 @@ function removeDuplicates(array, cb) {
7575
// removeDuplicates removes all duplicate values from the given array.
7676
// Pass the duplicate free array to the callback function.
7777
// Do not mutate the original array.
78+
return cb(array);
7879
}
80+
81+
const duplicates = (array) => {
82+
let newArr = [];
83+
array.forEach((element) => {
84+
if (newArr.includes(element)){
85+
console.log(`Duplicate element: ${element} skipped`);
86+
} else {
87+
newArr.push(element);
88+
}
89+
});
90+
console.log(newArr);
91+
}
92+
93+
removeDuplicates(items, duplicates);

0 commit comments

Comments
 (0)