Skip to content

Commit c10dccd

Browse files
committed
remove duplicates added
1 parent 0a9ecaf commit c10dccd

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Week3/js-exercises/ex2-RemoveDuplicates.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ does not return anything but removes any duplicate elements from the array.
1010
1111
*/
1212

13-
1413
// WRITE YOUR FUNCTION HERE
1514

1615
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
1716

18-
removeDuplicates(letter);
17+
function removeDuplicates(arr) {
18+
arr = arr.filter(function (item, index, inputArray) {
19+
return inputArray.indexOf(item) == index;
20+
});
21+
return arr;
22+
}
23+
24+
const newArray = removeDuplicates(letters);
1925

20-
if (letters === ['a', 'b', 'c', 'd', 'e', 'f'])
21-
console.log("Hooray!")
26+
if (JSON.stringify(newArray) === JSON.stringify(['a', 'b', 'c', 'd', 'e', 'f']))
27+
console.log('Hooray!');

0 commit comments

Comments
 (0)