Answers for "time conversion hacker rank soulutioin"

0

time conversion hacker rank soulutioin

let newArray = s.split(':')
    if(s.includes('PM')){
      
     if(newArray[0] < 12){
let newTime = Number(newArray[0]) + 12
let popElement = newArray.pop()
let slice = popElement.slice(-2)
let replace = popElement.replace(slice , '')
newArray[2] = replace
newArray[0] = newTime

return newArray.join(':') 

     }
if(newArray[0] == '12'){
    let popElement = newArray.pop()
let slice = popElement.slice(-2)
let replace = popElement.replace(slice , '')
newArray[2] = replace
return newArray.join(':')
}
else{
    let popElement = newArray.pop()
let slice = popElement.slice(-2)
let replace = popElement.replace(slice , '')
newArray[2] = replace
 return newArray.join(':')
}  
    }
    else if(s.includes('AM')){

        if(newArray[0] == 12){
            let newTime = newArray[0] - 12 + '' + 0
            let popElement = newArray.pop()
let slice = popElement.slice(-2)
let replace = popElement.replace(slice , '')
newArray[2] = replace
           newArray[0] = newTime
           return newArray.join(':')
        }
else {
    let popElement = newArray.pop()
let slice = popElement.slice(-2)
let replace = popElement.replace(slice , '')
newArray[2] = replace
   return newArray.join(':')
}
        
    }
// Paste this code inside the function.
Posted by: Guest on October-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language