Update formatting
This commit is contained in:
@ -5,14 +5,14 @@ firstSeen: 2018-01-23T20:48:46+02:00
|
||||
lastUpdated: 2020-10-22T20:23:47+03:00
|
||||
---
|
||||
|
||||
Creates a deep clone of an object.
|
||||
Creates a deep clone of an object.
|
||||
Clones primitives, arrays and objects, excluding class instances.
|
||||
|
||||
- Use recursion.
|
||||
- Check if the passed object is `null` and, if so, return `null`.
|
||||
- Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original.
|
||||
- Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.
|
||||
- If the object is an `Array`, set the `clone`'s `length` to that of the original and use `Array.from(clone)` to create a clone.
|
||||
- If the object is an `Array`, set the `clone`'s `length` to that of the original and use `Array.from()` to create a clone.
|
||||
|
||||
```js
|
||||
const deepClone = obj => {
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-20T23:02:01+03:00
|
||||
Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).
|
||||
|
||||
- Use `String.prototype.toLowerCase()` and `String.prototype.replace()` with an appropriate regular expression to remove unnecessary characters.
|
||||
- Use `String.prototype.split('')`, `Array.prototype.sort()` and `Array.prototype.join('')` on both strings to normalize them, then check if their normalized forms are equal.
|
||||
- Use `String.prototype.split()`, `Array.prototype.sort()` and `Array.prototype.join()` on both strings to normalize them, then check if their normalized forms are equal.
|
||||
|
||||
```js
|
||||
const isAnagram = (str1, str2) => {
|
||||
|
||||
@ -7,8 +7,8 @@ lastUpdated: 2020-10-21T21:54:53+03:00
|
||||
|
||||
Creates a new string with the results of calling a provided function on every character in the given string.
|
||||
|
||||
- Use `String.prototype.split('')` and `Array.prototype.map()` to call the provided function, `fn`, for each character in `str`.
|
||||
- Use `Array.prototype.join('')` to recombine the array of characters into a string.
|
||||
- Use `String.prototype.split()` and `Array.prototype.map()` to call the provided function, `fn`, for each character in `str`.
|
||||
- Use `Array.prototype.join()` to recombine the array of characters into a string.
|
||||
- The callback function, `fn`, takes three arguments (the current character, the index of the current character and the string `mapString` was called upon).
|
||||
|
||||
```js
|
||||
|
||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-22T20:23:26+03:00
|
||||
Checks if the given value is a number.
|
||||
|
||||
- Use `parseFloat()` to try to convert `n` to a number.
|
||||
- Use `!Number.isNaN()` to check if `num` is a number.
|
||||
- Use `Number.isNaN()` and logical not (`!`) operator to check if `num` is a number.
|
||||
- Use `Number.isFinite()` to check if `num` is finite.
|
||||
- Use `Number()` and the loose equality operator (`==`) to check if the coercion holds.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user