-
-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathdedupe.test.js
More file actions
52 lines (41 loc) · 1.61 KB
/
Copy pathdedupe.test.js
File metadata and controls
52 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const dedupe = require("./dedupe.js");
const findMax = require("./max.js");
/*
Dedupe Array
📖 Dedupe means **deduplicate**
In this kata, you will need to deduplicate the elements of an array
E.g. dedupe(['a','a','a','b','b','c']) returns ['a','b','c']
E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) returns [5, 1, 2, 3, 8]
E.g. dedupe([1, 2, 1]) returns [1, 2]
*/
// Acceptance Criteria:
// Given an empty array
// When passed to the dedupe function
// Then it should return an empty array
test("with input of empty array should return, empty array", () => {
let emptyArray = [];
expect(dedupe(emptyArray)).toEqual([]);
});
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
test("with input of array with no duplicates should return a copy of original array", () => {
const normalArray = [1, 2, 3, 4, 5, 6, 10];
const expected = [1, 2, 3, 4, 5, 6, 10]; // separate copy
const result = dedupe(normalArray);
// 1. Correct values
expect(result).toEqual(expected);
// 2. Different array in memory
expect(result).not.toBe(normalArray);
// 3. Original array not mutated
expect(normalArray).toEqual(expected);
}
);
// Given an array of strings or numbers
// When passed to the dedupe function
// Then it should return a new array with duplicates removed while preserving the
// first occurrence of each element from the original array.
test("with input of empty array should return, empty array", () => {
let mixValueArray = [1, 1, 1, 2, 2, "Hello", "Hello", "Hello", 3, 4, 4, 5];
expect(dedupe(mixValueArray)).toEqual([1, 2, "Hello", 3, 4, 5]);
});