Time Conversion

  • + 0 comments

    I wanna recieve feedback about my solution in Javascript, I've read other submissions and I know that my code is not de best solution but what things I need to know for code a better solution in a interview?

    function timeConversion(s) {
        // Write your code here
        s.trim() //delete blankspaces if there one
        switch (s[s.length-2]){
            case "A":
            {
                if(s[0]==="1"&&s[1]==="2"){
                    let aux=s.replace(`${s[0]}${s[1]}`,"00")
                    aux = aux.slice(0,s.length-2)
                    return aux
                }else{
                    s= s.slice(0,s.length-2)
                    return s
                }
            }
            case "P":
            {
               if(s[0]==="1"&&s[1]==="2"){
                    s= s.slice(0,s.length-2)
                    return s
                }else{
                let aux=s.slice(0,2)
                aux=(parseInt(aux))+12
                s= s.slice(0,s.length-2)
                s= s.replace(`${s[0]}${s[1]}`, aux.toString())
                return s
                }
            }
        }
    }