Update formatting
This commit is contained in:
@ -10,7 +10,7 @@ Returns the human-readable format of the given number of milliseconds.
|
||||
- Divide `ms` with the appropriate values to obtain the appropriate values for `day`, `hour`, `minute`, `second` and `millisecond`.
|
||||
- Use `Object.entries()` with `Array.prototype.filter()` to keep only non-zero values.
|
||||
- Use `Array.prototype.map()` to create the string for each value, pluralizing appropriately.
|
||||
- Use `String.prototype.join(', ')` to combine the values into a string.
|
||||
- Use `String.prototype.join()` to combine the values into a string.
|
||||
|
||||
```js
|
||||
const formatDuration = ms => {
|
||||
|
||||
@ -10,7 +10,7 @@ Returns the ISO format of the given number of seconds.
|
||||
- Divide `s` with the appropriate values to obtain the appropriate values for `hour`, `minute` and `second`.
|
||||
- Store the `sign` in a variable to prepend it to the result.
|
||||
- Use `Array.prototype.map()` in combination with `Math.floor()` and `String.prototype.padStart()` to stringify and format each segment.
|
||||
- Use `String.prototype.join(':')` to combine the values into a string.
|
||||
- Use `String.prototype.join()` to combine the values into a string.
|
||||
|
||||
```js
|
||||
const formatSeconds = s => {
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-19T22:49:51+03:00
|
||||
Retrieves a set of properties indicated by the given selectors from an object.
|
||||
|
||||
- Use `Array.prototype.map()` for each selector, `String.prototype.replace()` to replace square brackets with dots.
|
||||
- Use `String.prototype.split('.')` to split each selector.
|
||||
- Use `String.prototype.split()` to split each selector.
|
||||
- Use `Array.prototype.filter()` to remove empty values and `Array.prototype.reduce()` to get the value indicated by each selector.
|
||||
|
||||
```js
|
||||
|
||||
@ -9,7 +9,7 @@ Checks if the given string is a palindrome.
|
||||
|
||||
- Normalize the string to `String.prototype.toLowerCase()` and use `String.prototype.replace()` to remove non-alphanumeric characters from it.
|
||||
- Use the spread operator (`...`) to split the normalized string into individual characters.
|
||||
- Use `Array.prototype.reverse()`, `String.prototype.join('')` and compare the result to the normalized string.
|
||||
- Use `Array.prototype.reverse()`, `String.prototype.join()` and compare the result to the normalized string.
|
||||
|
||||
```js
|
||||
const palindrome = str => {
|
||||
|
||||
@ -7,8 +7,8 @@ lastUpdated: 2020-10-22T20:24:04+03:00
|
||||
|
||||
Parses an HTTP Cookie header string, returning an object of all cookie name-value pairs.
|
||||
|
||||
- Use `String.prototype.split(';')` to separate key-value pairs from each other.
|
||||
- Use `Array.prototype.map()` and `String.prototype.split('=')` to separate keys from values in each pair.
|
||||
- Use `String.prototype.split()` to separate key-value pairs from each other.
|
||||
- Use `Array.prototype.map()` and `String.prototype.split()` to separate keys from values in each pair.
|
||||
- Use `Array.prototype.reduce()` and `decodeURIComponent()` to create an object with all key-value pairs.
|
||||
|
||||
```js
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-09-18T21:19:23+03:00
|
||||
Reverses a number.
|
||||
|
||||
- Use `Object.prototype.toString()` to convert `n` to a string.
|
||||
- Use `String.prototype.split('')`, `Array.prototype.reverse()` and `String.prototype.join('')` to get the reversed value of `n` as a string.
|
||||
- Use `String.prototype.split()`, `Array.prototype.reverse()` and `String.prototype.join()` to get the reversed value of `n` as a string.
|
||||
- Use `parseFloat()` to convert the string to a number and `Math.sign()` to preserve its sign.
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user