Fix typos

This commit is contained in:
Chalarangelo
2022-09-04 13:49:46 +03:00
parent b95929d4e8
commit 126134a489
3 changed files with 3 additions and 3 deletions

View File

@ -10,7 +10,7 @@ lastUpdated: 2020-10-20T23:02:01+03:00
Returns the last element in an array.
- Check if `arr` is truthy and has a `length` property.
- Use `Array.prototype.length - 1` to compute the index of the last element of the given array and return it, otherwise return `undefined`.
- Use `Array.prototype.length` to compute the index of the last element of the given array and return it, otherwise return `undefined`.
```js
const last = arr => (arr && arr.length ? arr[arr.length - 1] : undefined);

View File

@ -10,7 +10,7 @@ firstSeen: 2022-06-16T05:00:00-04:00
Converts an object to a `Map`.
- Use `Object.entries` to convert the object to an array of key-value pairs.
- Use `Object.entries()` to convert the object to an array of key-value pairs.
- Use the `Map` constructor to convert the array to a `Map`.
```js

View File

@ -12,7 +12,7 @@ Replaces the last occurrence of a pattern in a string.
- Use `typeof` to determine if `pattern` is a string or a regular expression.
- If the `pattern` is a string, use it as the `match`.
- Otherwise, use the `RegeExp` constructor to create a new regular expression using the `RegExp.prototype.source` of the `pattern` and adding the `'g'` flag to it. Use `String.prototype.match()` and `Array.prototype.slice()` to get the last match, if any.
- Otherwise, use the `RegExp` constructor to create a new regular expression using the `RegExp.prototype.source` of the `pattern` and adding the `'g'` flag to it. Use `String.prototype.match()` and `Array.prototype.slice()` to get the last match, if any.
- Use `String.prototype.lastIndexOf()` to find the last occurrence of the match in the string.
- If a match is found, use `String.prototype.slice()` and a template literal to replace the matching substring with the given `replacement`.
- If no match is found, return the original string.