Skip to content

Commit 25d86f0

Browse files
committed
Implement dedupe function and add tests for empty and unique arrays
1 parent f7ce2f5 commit 25d86f0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎Sprint-1/implement/dedupe.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
function dedupe() {}
1+
function dedupe(list) {
2+
return list.filter((item, index) => index === list.indexOf(item));
3+
}
4+
5+
module.exports = dedupe;

‎Sprint-1/implement/dedupe.test.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ E.g. dedupe([1, 2, 1]) returns [1, 2]
1616
// Given an empty array
1717
// When passed to the dedupe function
1818
// Then it should return an empty array
19-
test.todo("given an empty array, it returns an empty array");
19+
test("given an empty array, it returns an empty array", () => {
20+
expect(dedupe([])).toEqual([]);
21+
});
22+
23+
test("given an array with no duplicates, it returns a copy of the original array", () => {
24+
expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]);
25+
});
2026

2127
// Given an array with no duplicates
2228
// When passed to the dedupe function
2329
// Then it should return a copy of the original array
2430

2531
// Given an array of strings or numbers
2632
// When passed to the dedupe function
27-
// Then it should return a new array with duplicates removed while preserving the
33+
// Then it should return a new array with duplicates removed while preserving the
2834
// first occurrence of each element from the original array.

0 commit comments

Comments
 (0)