Files
30-seconds-of-code/snippets/to12HourFormat.md
Michael Goldspinner 57357a4348 Guidelines fix
2018-01-12 10:17:39 -05:00

272 B

to12Hour

Uses the modulo operator (%) to transform an integer to a 12 hour clock format.

const to12Hour = ( num ) => {

    return num === 0 || num === 12 || num === 24 ? 12 : num % 12;
}
// to12Hour(9) -> "9"
// to12Hour(9) -> "9"
// to12Hour(13) -> "1"