@@ -13,15 +13,31 @@ E.g. dedupe([1, 2, 1]) target output: [1, 2]
1313
1414// Acceptance Criteria:
1515
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" ) ;
20-
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
24-
25- // Given an array with strings or numbers
26- // When passed to the dedupe function
27- // Then it should remove the duplicate values, preserving the first occurence of each element
16+ describe ( "dedupe" , ( ) => {
17+ // Given an empty array
18+ // When passed to the dedupe function
19+ // Then it should return an empty array
20+ test ( "given an empty array, it returns an empty array" , ( ) => {
21+ expect ( dedupe ( [ ] ) ) . toEqual ( [ ] ) ;
22+ } ) ;
23+
24+ // Given an array with no duplicates
25+ // When passed to the dedupe function
26+ // Then it should return a copy of the original array
27+ test ( "returns a copy when no duplicates exist" , ( ) => {
28+ const input = [ 1 , 2 , 3 ] ;
29+ const output = dedupe ( input ) ;
30+
31+ expect ( output ) . toEqual ( [ 1 , 2 , 3 ] ) ;
32+ expect ( output ) . not . toBe ( input ) ; // ensures it's a new array, not the same reference
33+ } ) ;
34+
35+ // Given an array with strings or numbers
36+ // When passed to the dedupe function
37+ // Then it should remove the duplicate values, preserving the first occurrence
38+ test ( "removes duplicates and preserves first occurrence" , ( ) => {
39+ expect ( dedupe ( [ 'a' , 'a' , 'a' , 'b' , 'b' , 'c' ] ) ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ;
40+ expect ( dedupe ( [ 5 , 1 , 1 , 2 , 3 , 2 , 5 , 8 ] ) ) . toEqual ( [ 5 , 1 , 2 , 3 , 8 ] ) ;
41+ expect ( dedupe ( [ 1 , 2 , 1 ] ) ) . toEqual ( [ 1 , 2 ] ) ;
42+ } ) ;
43+ } ) ;
0 commit comments