From eb2692fadacd352af397327b4a821e6f008fe808 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Sat, 8 Sep 2018 12:25:15 +0000 Subject: [PATCH] Travis build: 402 --- docs/browser.html | 2 +- docs/index.html | 2 +- docs/math.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/browser.html b/docs/browser.html index 1e14397dd..05fe55088 100644 --- a/docs/browser.html +++ b/docs/browser.html @@ -205,7 +205,7 @@ hub.off
insertBefore(document.getElementById('myId'), '<p>before</p>'); // <p>before</p> <div id="myId">...</div>
 
intermediate

isBrowserTabFocused

Returns true if the browser tab of the page is focused, false otherwise.

Use the Document.hidden property, introduced by the Page Visibility API to check if the browser tab of the page is visible or hidden.

const isBrowserTabFocused = () => !document.hidden;
 
isBrowserTabFocused(); // true
-
intermediate

nodeListToArray

Converts a NodeList to an array.

Use Array.prototype.slice() and Function.prototype.call() to convert a NodeList to an array.

const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
+
intermediate

nodeListToArray

Converts a NodeList to an array.

Use spread operator inside new array to convert a NodeList to an array.

const nodeListToArray = nodeList => [...nodeList];
 
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
 
advanced

observeMutations

Returns a new MutationObserver and runs the provided callback for each mutation on the specified element.

Use a MutationObserver to observe mutations on the given element. Use Array.forEach() to run the callback for each mutation that is observed. Omit the third argument, options, to use the default options (all true).

const observeMutations = (element, callback, options) => {
   const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)));
diff --git a/docs/index.html b/docs/index.html
index 093437826..261548c19 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -218,7 +218,7 @@
 };
 
intersection([1, 2, 3], [4, 3, 2]); // [2,3]
 
intermediate

intersectionBy

Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.

Create a Set by applying fn to all elements in b, then use Array.filter() on a to only keep elements, which produce values contained in b when fn is applied to them.

const intersectionBy = (a, b, fn) => {
-  const s = new Set(b.map(x => fn(x)));
+  const s = new Set(b.map(fn));
   return a.filter(x => s.has(fn(x)));
 };
 
intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1]
diff --git a/docs/math.html b/docs/math.html
index edb086d33..ad8614262 100644
--- a/docs/math.html
+++ b/docs/math.html
@@ -232,7 +232,7 @@ own individual rating by supplying it as the third argument.
 
randomIntegerInRange(0, 5); // 2
 
intermediate

randomNumberInRange

Returns a random number in the specified range.

Use Math.random() to generate a random value, map it to the desired range using multiplication.

const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
 
randomNumberInRange(2, 10); // 6.0211363285087005
-
intermediate

round

Rounds a number to a specified amount of digits.

Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals to round to an integer.

const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
+
intermediate

round

Rounds a number to a specified amount of digits.

Use Math.round() and template literals to round the number to the specified number of digits. Omit the second argument, decimals to round to an integer.

const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
 
round(1.005, 2); // 1.01
 
intermediate

sdbm

Hashes the input string into a whole number.

Use String.split('') and Array.reduce() to create a hash of the input string, utilizing bit shifting.

const sdbm = str => {
   let arr = str.split('');