diff --git a/snippets/transform-integer-to-12-hour-format.md b/snippets/transform-integer-to-12-hour-format.md new file mode 100644 index 000000000..865aaa0a3 --- /dev/null +++ b/snippets/transform-integer-to-12-hour-format.md @@ -0,0 +1,14 @@ +### Transform Int (12 Hour Format) + +Use the modulo operator (`%`) to transform an integer to a 12 hour clock format. + +```js +const to12Hour = ( int ) => { + int = parseInt(int); + + return int === 0 || int === 12 || int === 24 ? 12 : int % 12; +} +// to12Hour(9) -> "9" +// to12Hour(9) -> "9" +// to12Hour(13) -> "1" +``` \ No newline at end of file