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- ) {
2+ if ( object === null || typeof object !== "object" || Array . isArray ( object ) ) {
83 return false ;
94 }
105
116 if ( Object . keys ( object ) . length === 0 ) {
127 return false ;
138 }
149
15- for ( const item in object ) {
16- if ( Array . isArray ( object [ item ] ) ) {
17- return false ;
18- }
19- }
20-
2110 for ( const item in object ) {
2211 if ( item === key ) {
2312 return true ;
2413 }
2514 }
26-
2715 return false ;
2816}
2917
Original file line number Diff line number Diff line change @@ -51,9 +51,9 @@ test("should return false if the input object do not have non existing key value
5151// Given invalid parameters like an array
5252// When passed to contains
5353// Then it should return false or throw an error
54- test ( "should return false if the input object do not have non existing key value " , ( ) => {
54+ test ( "should return false if the input parameters is an array or not an object " , ( ) => {
5555 let mixObject = { a : 2 , b : "hello" , c : [ ] } ;
56- expect ( contains ( mixObject , "c" ) ) . toBe ( false ) ;
56+ expect ( contains ( mixObject , "c" ) ) . toBe ( true ) ;
5757 expect ( contains ( [ "A" , "B" ] , "1" ) ) . toBe ( false ) ;
5858 expect ( contains ( null , "1" ) ) . toBe ( false ) ;
5959 expect ( contains ( undefined , "1" ) ) . toBe ( false ) ;
Original file line number Diff line number Diff line change 11function tally ( sumArray ) {
2- if ( sumArray . length === 0 ) return { } ;
32 if ( ! Array . isArray ( sumArray ) ) {
43 throw new Error ( "Input musk be an array" ) ;
54 }
5+
6+ if ( sumArray . length === 0 ) return { } ;
7+
68 let totalSum = { } ;
79 for ( const item of sumArray ) {
810 if ( ! Object . hasOwn ( totalSum , item ) ) {
Original file line number Diff line number Diff line change 44 < meta charset ="utf-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
66 < link rel ="stylesheet " href ="style.css " />
7- < title > Alarm clock app </ title >
7+ < title > Title here </ title >
88 </ head >
99 < body >
1010 < div class ="centre ">
You can’t perform that action at this time.
0 commit comments