@@ -16,7 +16,6 @@ E.g. dedupe([1, 2, 1]) target output: [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" ) ;
2019
2120// Given an array with no duplicates
2221// When passed to the dedupe function
@@ -25,3 +24,23 @@ test.todo("given an empty array, it returns an empty array");
2524// Given an array with strings or numbers
2625// When passed to the dedupe function
2726// Then it should remove the duplicate values, preserving the first occurence of each element
27+
28+ describe ( "dedupe" , ( ) => {
29+ [
30+ { input : [ ] , expected : [ ] } ,
31+ { input : [ "apple" , "banana" , 1 , 10 ] , expected : [ "apple" , "banana" , 1 , 10 ] } ,
32+ {
33+ input : [ 1 , - 1 , - 100 , - 100 , "apple" , "apple" ] ,
34+ expected : [ 1 , - 1 , - 100 , "apple" ] ,
35+ } ,
36+ { input : [ - 10 , - 20 , - 3 , - 4 ] , expected : [ - 10 , - 20 , - 3 , - 4 ] } ,
37+ { input : [ 1.5 , 10.5 , 0.5 ] , expected : [ 1.5 , 10.5 , 0.5 ] } ,
38+ {
39+ input : [ "apple" , "banana" , "cherry" ] ,
40+ expected : [ "apple" , "banana" , "cherry" ] ,
41+ } ,
42+ ] . forEach ( ( { input, expected } ) =>
43+ it ( `returns the deduped array for [${ input } ]` , ( ) =>
44+ expect ( dedupe ( input ) ) . toEqual ( expected ) )
45+ ) ;
46+ } ) ;
0 commit comments