File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function contains ( object , key ) {
2+ if (
3+ object === null ||
4+ object === undefined ||
5+ typeof object !== "object" ||
6+ Array . isArray ( object )
7+ ) {
8+ return false ;
9+ }
10+
211 if ( Object . keys ( object ) . length === 0 ) {
312 return false ;
413 }
514
6- for ( const checkItem in object ) {
7- let validation = object [ checkItem ] ;
8- if ( Array . isArray ( validation ) ) {
15+ for ( const item in object ) {
16+ if ( Array . isArray ( object [ item ] ) ) {
917 return false ;
1018 }
1119 }
20+
1221 for ( const item in object ) {
1322 if ( item === key ) {
1423 return true ;
1524 }
1625 }
26+
1727 return false ;
1828}
1929
Original file line number Diff line number Diff line change @@ -54,4 +54,10 @@ test("should return false if the input object do not have non existing key value
5454test ( "should return false if the input object do not have non existing key value" , ( ) => {
5555 let mixObject = { a : 2 , b : "hello" , c : [ ] } ;
5656 expect ( contains ( mixObject , "c" ) ) . toBe ( false ) ;
57+
58+
59+ expect ( contains ( [ "A" , "B" ] , "1" ) ) . toBe ( false ) ;
60+ expect ( contains ( null , "1" ) ) . toBe ( false ) ;
61+ expect ( contains ( undefined , "1" ) ) . toBe ( false ) ;
62+ expect ( contains ( "ABC" , "1" ) ) . toBe ( false ) ;
5763} ) ;
You can’t perform that action at this time.
0 commit comments