DEV Community


Posted on

code every day with me

--DAY 3--
Hi, I am going to make #100DaysOfCode Challenge.Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
-Problem: Time Conversion
-My solution (javascript):

function timeConversion(s) {
    let check=s[s.length-2];
    s=s.substr(0, s.length-2).split(':');
    if(Number(s[0])==12) {
        if(check=='A') {
            return s.join(':');
        else return s.join(':')
    if(check=='P') s[0]=(Number(s[0])+12).toString();
    return s.join(':');
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Top comments (0)