Created
August 14, 2017 19:22
-
-
Save Horaddrim/4ab014078408b2c97485ffdc88c6db54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inverteString = (stringOriginal) => | |
{ | |
let aux = ""; | |
let size = stringOriginal.length; | |
for(i = (size - 1); i <= (size) && i >=0; i--) | |
{ | |
aux += stringOriginal[i]; | |
//console.log(aux); | |
} | |
return aux; | |
}; | |
let IsMorning = function(stringOriginal) | |
{ | |
aux = stringOriginal.search('AM'); | |
let reducao; | |
if(stringOriginal[aux]) | |
{ | |
reducao = true; | |
} | |
else | |
{ | |
reducao = false; | |
} | |
return reducao; | |
}; | |
let getDate = stringOriginal => { return stringOriginal.substring(0, 2); }; | |
const convertTime = timeString => | |
{ | |
timeString = timeString.trim(); | |
//timeString = timeString.replace(':','').replace(':',''); | |
let novoHorario = parseInt(getDate(timeString)); | |
if(IsMorning(timeString)) | |
{ | |
if(novoHorario != 12) | |
{ | |
novoHorario = 00.toString() + novoHorario; | |
timeString = novoHorario.toString() + timeString.substring(2,8); | |
} | |
else | |
{ | |
timeString = novoHorario.toString() + timeString.substring(2,8); | |
} | |
} | |
else | |
{ | |
novoHorario = novoHorario + 12; | |
timeString = novoHorario.toString() + timeString.substring(2,8); | |
} | |
if(parseInt(getDate(timeString)) == 24) | |
{ | |
timeString = "00"+ timeString.substring(2,8); | |
} | |
return timeString; | |
}; | |
//Assertividade! | |
console.log(inverteString('MindFuck')); | |
console.log(convertTime('07:45:05PM')); | |
console.log(convertTime('07:45:05AM')); | |
console.log(convertTime('12:00:00PM')); | |
console.log(convertTime('12:00:00AM')); | |
console.log(convertTime('08:00:00PM')); | |
console.log(convertTime('08:00:00AM')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment