We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functiontimeConversion(s){// Write your code herelettime=s.slice(0,8).split(':');letformat=s.slice(8);if(format==='PM'&&time[0]!=='12'){time[0]=(parseInt(time[0])+12).toString();}elseif(format==='AM'&&time[0]==='12'){time[0]='00';}// Pad hours, minutes, and seconds to ensure two digitsfor(leti=0;i<time.length;i++){time[i]=time[i].padStart(2,'0');}returntime.join(':');}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
my approach on the JavaScript solution