Fixes to Submitted Functions
Fixed formatting of both snippet files.
This commit is contained in:
@ -1,13 +0,0 @@
|
|||||||
### toColonTime
|
|
||||||
|
|
||||||
Returns transformed time integers from provided date object to "colon time" representation. Formats hour to 12 hour and maintains digit length of colon time format (HH:MM:SS).
|
|
||||||
|
|
||||||
```js
|
|
||||||
let toColonTime = ( date ) => {
|
|
||||||
let times = [ date.getHours(), date.getMinutes(), date.getSeconds() ];
|
|
||||||
times[0] = times[0] === 0 || times[0] === 12 || times[0] === 24 ? 12 : times[0] % 12;
|
|
||||||
|
|
||||||
return times.map( time => time.toString().padStart(2, "0") ).join(":");
|
|
||||||
}
|
|
||||||
// toColonTime12(new Date()) -> "08:38:00"
|
|
||||||
```
|
|
||||||
16
snippets/getColonTimeFromDate.md
Normal file
16
snippets/getColonTimeFromDate.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
### getColonTimeFromDate
|
||||||
|
|
||||||
|
Formats hour, minute, and second time integers from Date into stringified colon representation. Formats hour integer to 12 hour clock and maintains digit lengths to match (HH:MM:SS).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const getColonTimeFromDate = date => {
|
||||||
|
let times = [ date.getHours(), date.getMinutes(), date.getSeconds() ];
|
||||||
|
times[0] = times[0] === 0 || times[0] === 12 || times[0] === 24 ? 12 : times[0] % 12;
|
||||||
|
|
||||||
|
return times.map( time => time.toString().padStart(2, "0") ).join(":");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
getColonTimeFromDate(new Date()) // "08:38:00"
|
||||||
|
```
|
||||||
@ -1,15 +0,0 @@
|
|||||||
### toMeridiem
|
|
||||||
|
|
||||||
Uses modulo operator (`%`) to transform an integer to a 12 hour clock format. Stringifies transformed integer with concatenated meridiem suffix. Maintains 12 hour format principles with conditional check (0am - 12am).
|
|
||||||
|
|
||||||
```js
|
|
||||||
const toMeridiem = num => {
|
|
||||||
const meridiems = ["am", "pm"];
|
|
||||||
let period = num > 11 ? 1 : 2;
|
|
||||||
|
|
||||||
return num === 0 || num === 12 || num === 24 ? 12 + meridiems[period] : num % 12 + meridiems[period];
|
|
||||||
}
|
|
||||||
// toMeridiem(0) -> "12am"
|
|
||||||
// toMeridiem(9) -> "9am"
|
|
||||||
// toMeridiem(13) -> "1pm"
|
|
||||||
```
|
|
||||||
16
snippets/getMeridiemSuffixOfInteger.md
Normal file
16
snippets/getMeridiemSuffixOfInteger.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
### getMeridiemSuffixOfInteger
|
||||||
|
|
||||||
|
Uses modulo (`%`) and conditional checks to transform integer to a stringified 12 hour format with meridiem suffix. Conditionals maintain 12 hour principles (0am - 12am).
|
||||||
|
|
||||||
|
Does not handle integers not representing an hour time (ie: 25, 1000, etc...)
|
||||||
|
|
||||||
|
```js
|
||||||
|
const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + "am" : num === 12 ? 12 + "pm" : num < 12 ? (num % 12) + "am" : (num % 12) + "pm";
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
getMeridiemSuffixOfInteger(0) // "12am"
|
||||||
|
getMeridiemSuffixOfInteger(11) // "11am"
|
||||||
|
getMeridiemSuffixOfInteger(13) // "1pm"
|
||||||
|
getMeridiemSuffixOfInteger(25) // "1pm"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user