Skip to content

Commit 1d434da

Browse files
committed
complete implementation of dedupe.js and test
1 parent ca8c1ce commit 1d434da

2 files changed

Lines changed: 51 additions & 21 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 [...new Set(list)];
3+
}
4+
5+
module.exports = dedupe;

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

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
11
const dedupe = require("./dedupe.js");
2-
/*
3-
Dedupe Array
42

5-
📖 Dedupe means **deduplicate**
3+
//Dedupe Array
64

7-
In this kata, you will need to deduplicate the elements of an array
5+
//📖 Dedupe means **deduplicate**
86

9-
E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c']
10-
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8]
11-
E.g. dedupe([1, 2, 1]) returns [1, 2]
12-
*/
7+
//In this kata, you will need to deduplicate the elements of an array
138

14-
// Acceptance Criteria:
9+
describe("dedupe", () => {
10+
//E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c']
11+
it("returns for ['a','a','a','b','b','c']", () => {
12+
expect(dedupe(["a", "a", "a", "b", "b", "c"])).toEqual(["a", "b", "c"]);
13+
});
1514

16-
// Given an empty array
17-
// When passed to the dedupe function
18-
// Then it should return an empty array
19-
test.todo("given an empty array, it returns an empty array");
15+
//E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8]
16+
it("returns for [5, 1, 1, 2, 3, 2, 5, 8]", () => {
17+
expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]);
18+
});
19+
//E.g. dedupe([1, 2, 1]) returns [1, 2]
20+
//*/
21+
it("returns for [1, 2, 1]", () => {
22+
expect(dedupe([1, 2, 1])).toEqual([1, 2]);
23+
});
2024

21-
// Given an array with no duplicates
22-
// When passed to the dedupe function
23-
// Then it should return a copy of the original array
25+
// Acceptance Criteria:
2426

25-
// Given an array of strings or numbers
26-
// When passed to the dedupe function
27-
// Then it should return a new array with duplicates removed while preserving the
28-
// first occurrence of each element from the original array.
27+
// Given an empty array
28+
// When passed to the dedupe function
29+
// Then it should return an empty array
30+
31+
it("returns for []", () => {
32+
expect(dedupe([])).toEqual([]);
33+
});
34+
35+
// Given an array with no duplicates
36+
// When passed to the dedupe function
37+
// Then it should return a copy of the original array
38+
39+
it("returns for [1, 2, 3, 4]", () => {
40+
expect(dedupe([1, 2, 3, 4])).toEqual([1, 2, 3, 4]);
41+
});
42+
43+
// Given an array of strings or numbers
44+
// When passed to the dedupe function
45+
// Then it should return a new array with duplicates removed while preserving the
46+
// first occurrence of each element from the original array.
47+
it("returns for ['apple', 'orange', 'banana', 'banana']", () => {
48+
expect(dedupe(["apple", "orange", "banana", "banana"])).toEqual([
49+
"apple",
50+
"orange",
51+
"banana",
52+
]);
53+
});
54+
});

0 commit comments

Comments
 (0)