From 008105c181d1b247ab12f949ba38df6b3d524ba5 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 30 Jan 2022 12:44:55 +0200 Subject: [PATCH] Update formatting --- snippets/deepClone.md | 4 ++-- snippets/isAnagram.md | 2 +- snippets/mapString.md | 4 ++-- snippets/validateNumber.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/snippets/deepClone.md b/snippets/deepClone.md index fd7d49193..1b758c089 100644 --- a/snippets/deepClone.md +++ b/snippets/deepClone.md @@ -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 => { diff --git a/snippets/isAnagram.md b/snippets/isAnagram.md index 69dc12957..afe6845c8 100644 --- a/snippets/isAnagram.md +++ b/snippets/isAnagram.md @@ -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) => { diff --git a/snippets/mapString.md b/snippets/mapString.md index 08e5068a0..8c93452fb 100644 --- a/snippets/mapString.md +++ b/snippets/mapString.md @@ -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 diff --git a/snippets/validateNumber.md b/snippets/validateNumber.md index bbeb6201d..beefebc12 100644 --- a/snippets/validateNumber.md +++ b/snippets/validateNumber.md @@ -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.