@@ -20,15 +20,35 @@ test("given an empty array, it returns an empty array", () => {
2020 expect ( dedupe ( [ ] ) ) . toEqual ( [ ] ) ;
2121} ) ;
2222
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- } ) ;
26-
2723// Given an array with no duplicates
2824// When passed to the dedupe function
2925// Then it should return a copy of the original array
3026
27+ test ( "given an array with no duplicates, it returns a copy of the original array" , ( ) => {
28+ const input = [ 1 , 2 , 3 ] ;
29+ const result = dedupe ( input ) ;
30+
31+ expect ( result ) . toEqual ( input ) ;
32+ expect ( result ) . not . toBe ( input ) ;
33+ } ) ;
34+
3135// Given an array of strings or numbers
3236// When passed to the dedupe function
3337// Then it should return a new array with duplicates removed while preserving the
3438// first occurrence of each element from the original array.
39+
40+ test ( "given an array of numbers with duplicates, it returns a new array with duplicates removed preserving first occurrences" , ( ) => {
41+ const input = [ 5 , 1 , 1 , 2 , 3 , 2 , 5 , 8 ] ;
42+ const result = dedupe ( input ) ;
43+
44+ expect ( result ) . toEqual ( [ 5 , 1 , 2 , 3 , 8 ] ) ;
45+ expect ( result ) . not . toBe ( input ) ;
46+ } ) ;
47+
48+ test ( "given an array of strings with duplicates, it returns a new array with duplicates removed preserving first occurrences" , ( ) => {
49+ const input = [ "a" , "a" , "a" , "b" , "b" , "c" ] ;
50+ const result = dedupe ( input ) ;
51+
52+ expect ( result ) . toEqual ( [ "a" , "b" , "c" ] ) ;
53+ expect ( result ) . not . toBe ( input ) ;
54+ } ) ;
0 commit comments