diff --git a/README.md b/README.md index a55c96372..e0046efe5 100644 --- a/README.md +++ b/README.md @@ -2668,11 +2668,11 @@ clampNumber(1, -1, -5); // -1 Converts a number to an array of digits. -Convert the number to a string, using spread operators in ES6(`[...string]`) build an array. +Convert the number to a string, using the spread operator (`...`) to build an array. Use `Array.map()` and `parseInt()` to transform each value to an integer. ```js -const digitize = n => [...('' + n)].map(i => parseInt(i)); +const digitize = n => [...`${n}`].map(i => parseInt(i)); ```
@@ -4122,6 +4122,7 @@ Combine characters to get a string using `String.join('')`. ```js + const reverseString = str => [..str] .reverse() diff --git a/docs/index.html b/docs/index.html index 537e1f41f..b24a19120 100644 --- a/docs/index.html +++ b/docs/index.html @@ -543,7 +543,7 @@ document.bodyclipboard Copy to clipboard

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
 
clampNumber(2, 3, 5); // 3
 clampNumber(1, -1, -5); // -1
-

digitize

Converts a number to an array of digits.

Convert the number to a string, using spread operators in ES6([...string]) build an array. Use Array.map() and parseInt() to transform each value to an integer.

const digitize = n => [...('' + n)].map(i => parseInt(i));
+

digitize

Converts a number to an array of digits.

Convert the number to a string, using the spread operator (...) to build an array. Use Array.map() and parseInt() to transform each value to an integer.

const digitize = n => [...`${n}`].map(i => parseInt(i));
 
digitize(123); // [1, 2, 3]
 

distance

Returns the distance between two points.

Use Math.hypot() to calculate the Euclidean distance between two points.

const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
 
distance(1, 1, 2, 3); // 2.23606797749979
@@ -874,6 +874,7 @@ console.log<
 autoPluralize(2, 'person'); // 'people'
 

reverseString

Reverses a string.

Use the spread operator (...) and Array.reverse() to reverse the order of the characters in the string. Combine characters to get a string using String.join('').

 
+
 const reverseString = str =>
   [..str]
     .reverse()
diff --git a/snippets/reverseString.md b/snippets/reverseString.md
index cde5dd825..befdd8bf5 100644
--- a/snippets/reverseString.md
+++ b/snippets/reverseString.md
@@ -8,6 +8,7 @@ Combine characters to get a string using `String.join('')`.
 ```js
 
 
+
 const reverseString = str =>
   [..str]
     .reverse()