|
1 | 1 | const dedupe = require("./dedupe.js"); |
2 | | -/* |
3 | | -Dedupe Array |
4 | 2 |
|
5 | | -📖 Dedupe means **deduplicate** |
| 3 | +//Dedupe Array |
6 | 4 |
|
7 | | -In this kata, you will need to deduplicate the elements of an array |
| 5 | +//📖 Dedupe means **deduplicate** |
8 | 6 |
|
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 |
13 | 8 |
|
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 | + }); |
15 | 14 |
|
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 | + }); |
20 | 24 |
|
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: |
24 | 26 |
|
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