@@ -39,8 +39,8 @@ describe("findMax", () => {
3939 // Given an array with non-number values
4040 // When passed to the max function
4141 // Then it should return the max and ignore non-numeric values
42- test ( "ignores non-number values" , ( ) => {
43- expect ( findMax ( [ "hey" , 10 , "hi " , 60 , 10 ] ) ) . toBe ( 60 ) ;
42+ test ( "ignores non-number values (including numeric strings) " , ( ) => {
43+ expect ( findMax ( [ "hey" , 10 , "300 " , 60 , 10 ] ) ) . toBe ( 60 ) ;
4444 } ) ;
4545
4646 // Given an array with only non-number values
@@ -49,4 +49,20 @@ describe("findMax", () => {
4949 test ( "returns -Infinity when array has only non-number values" , ( ) => {
5050 expect ( findMax ( [ "a" , "b" , "c" ] ) ) . toBe ( - Infinity ) ;
5151 } ) ;
52+
53+ test ( "does not treat numeric strings as numbers" , ( ) => {
54+ expect ( findMax ( [ 20 , "300" ] ) ) . toBe ( 20 ) ;
55+ } ) ;
56+
57+ test ( "returns -Infinity when only numeric strings are present" , ( ) => {
58+ expect ( findMax ( [ "100" , "200" , "300" ] ) ) . toBe ( - Infinity ) ;
59+ } ) ;
60+
61+ test ( "ignores NaN and Infinity values" , ( ) => {
62+ expect ( findMax ( [ 10 , NaN , 50 , Infinity , - Infinity ] ) ) . toBe ( 50 ) ;
63+ } ) ;
64+
65+ test ( "returns -Infinity when only NaN and Infinity are present" , ( ) => {
66+ expect ( findMax ( [ NaN , Infinity , - Infinity ] ) ) . toBe ( - Infinity ) ;
67+ } ) ;
5268} ) ;
0 commit comments