File tree Expand file tree Collapse file tree
Sprint-2/5-stretch-extend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function formatAs12HourClock ( time ) {
2- const timeParts = time . split ( ":" ) ;
3- const mins = timeParts [ 1 ] . padStart ( 2 , "0" ) ;
4- const hoursInt = Number ( timeParts [ 0 ] ) ;
5- if ( hoursInt === 0 ) return `${ 12 } :${ mins } am` ;
6- if ( hoursInt < 12 ) return `${ timeParts [ 0 ] . padStart ( 2 , "0" ) } :${ mins } am` ;
7- if ( hoursInt === 12 )
8- return `${ timeParts [ 0 ] } :${ timeParts [ 1 ] . padStart ( 2 , "0" ) } pm` ;
2+ const [ hours , minutes ] = time . split ( ":" ) ;
3+ const mins = minutes . padStart ( 2 , "0" ) ;
4+ const hoursInt = Number ( hours ) ;
5+ if ( hoursInt === 0 ) {
6+ return `${ 12 } :${ mins } am` ;
7+ }
8+ if ( hoursInt < 12 ) {
9+ return `${ hours . padStart ( 2 , "0" ) } :${ mins } am` ;
10+ }
11+ if ( hoursInt === 12 ) {
12+ return `${ hours } :${ mins } pm` ;
13+ }
914 return `${ ( hoursInt - 12 ) . toString ( ) . padStart ( 2 , "0" ) } :${ mins } pm` ;
1015}
1116
Original file line number Diff line number Diff line change 99 "keywords" : [],
1010 "author" : " Code Your Future" ,
1111 "license" : " ISC" ,
12- "dependencies " : {
13- "jest" : " ^29.7.0 "
12+ "devDependencies " : {
13+ "jest" : " ^30.4.2 "
1414 }
15- }
15+ }
You can’t perform that action at this time.
0 commit comments