Update formatting

This commit is contained in:
Isabelle Viktoria Maciohsek
2022-01-30 18:34:30 +02:00
parent 1c0190b1ad
commit ae1828e42f
6 changed files with 8 additions and 8 deletions

View File

@ -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`. - 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 `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 `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 ```js
const formatDuration = ms => { const formatDuration = ms => {

View File

@ -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`. - 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. - 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 `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 ```js
const formatSeconds = s => { const formatSeconds = s => {

View File

@ -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. 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 `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. - Use `Array.prototype.filter()` to remove empty values and `Array.prototype.reduce()` to get the value indicated by each selector.
```js ```js

View File

@ -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. - 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 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 ```js
const palindrome = str => { const palindrome = str => {

View File

@ -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. 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 `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.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. - Use `Array.prototype.reduce()` and `decodeURIComponent()` to create an object with all key-value pairs.
```js ```js

View File

@ -8,11 +8,11 @@ lastUpdated: 2020-09-18T21:19:23+03:00
Reverses a number. Reverses a number.
- Use `Object.prototype.toString()` to convert `n` to a string. - 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. - Use `parseFloat()` to convert the string to a number and `Math.sign()` to preserve its sign.
```js ```js
const reverseNumber = n => const reverseNumber = n =>
parseFloat(`${n}`.split('').reverse().join('')) * Math.sign(n); parseFloat(`${n}`.split('').reverse().join('')) * Math.sign(n);
``` ```