Time Conversion

  • + 0 comments

    My solution in javascript :

    function timeConversion(s) {
        // Write your code here
        const ampm = s.slice(-2)
        const h = s.slice(0,2)
        const rest = s.slice(2,-2)
        // console.log(n) // 12
        // console.log(t) // "PM"
        if ( ampm === "PM" ) {
         return h === "12" ? `12${rest}` : `${String(Number(h) + 12)}${rest}`
        } else {
          return h === "12" ? `00${rest}` : `${h}${rest}`
        }
    }