@@ -16,13 +16,46 @@ E.g. dedupe([1, 2, 1]) returns [1, 2]
1616// Given an empty array
1717// When passed to the dedupe function
1818// Then it should return an empty array
19- test . todo ( "given an empty array, it returns an empty array" ) ;
19+ test ( "given an empty array, return an empty array" , ( ) => {
20+ expect ( dedupe ( [ ] ) ) . toEqual ( [ ] ) ;
21+ } ) ;
2022
2123// Given an array with no duplicates
2224// When passed to the dedupe function
2325// Then it should return a copy of the original array
26+ const testCaseNoDuplicates = [
27+ {
28+ input : [ "hey" , "buddy" , "world" , "10" , "sister" , 1 ] ,
29+ expected : [ "hey" , "buddy" , "world" , "10" , "sister" , 1 ] ,
30+ } ,
31+ {
32+ input : [ 2 , 3 , 4 , 5 , 6 , 7 ] ,
33+ expected : [ 2 , 3 , 4 , 5 , 6 , 7 ] ,
34+ } ,
35+ ] ;
36+ testCaseNoDuplicates . forEach ( ( { input, expected } ) => {
37+ test ( "given an array with no duplicates, return a copy of the array" , ( ) => {
38+ expect ( dedupe ( input ) ) . toEqual ( expected ) ;
39+ } ) ;
40+ } ) ;
2441
2542// Given an array of strings or numbers
2643// When passed to the dedupe function
27- // Then it should return a new array with duplicates removed while preserving the
44+ // Then it should return a new array with duplicates removed while preserving the
2845// first occurrence of each element from the original array.
46+ const testCaseWithDuplicates = [
47+ { input : [ 1 , 2 , 2 , 3 , 1 ] , expected : [ 1 , 2 , 3 ] } ,
48+ { input : [ "a" , "b" , "a" , "c" , "b" ] , expected : [ "a" , "b" , "c" ] } ,
49+ { input : [ 5 , 5 , 1 , 1 , 2 , 3 , 2 ] , expected : [ 5 , 1 , 2 , 3 ] } ,
50+ {
51+ input : [ "apple" , "banana" , "apple" , "orange" ] ,
52+ expected : [ "apple" , "banana" , "orange" ] ,
53+ } ,
54+ { input : [ 1 , "a" , 1 , "b" , "a" , 2 ] , expected : [ 1 , "a" , "b" , 2 ] } ,
55+ { input : [ "hey" , "hey" , "hey" , "hey" , "hey" , "hey" ] , expected : [ "hey" ] } ,
56+ ] ;
57+ testCaseWithDuplicates . forEach ( ( { input, expected } ) => {
58+ test ( "given an array with duplicates, return a new array with only the first occurrence" , ( ) => {
59+ expect ( dedupe ( input ) ) . toEqual ( expected ) ;
60+ } ) ;
61+ } ) ;
0 commit comments