From afe2e11ee47572f3c8601003507b1e585ae2a0da Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Sat, 12 Jan 2019 09:53:39 +0000 Subject: [PATCH] Travis build: 950 --- README.md | 8 ++++---- docs/adapter.html | 2 +- docs/index.html | 6 +++--- snippets/pipeAsyncFunctions.md | 2 +- snippets/remove.md | 6 +++--- test/_30s.js | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d6a5edcd7..6431a9bea 100644 --- a/README.md +++ b/README.md @@ -672,7 +672,7 @@ const sum = pipeAsyncFunctions( x => x + 3, async x => (await x) + 4 ); -(async() => { +(async () => { console.log(await sum(5)); // 15 (after one second) })(); ``` @@ -2317,9 +2317,9 @@ The `func` is invoked with three arguments (`value, index, array`). const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; ``` diff --git a/docs/adapter.html b/docs/adapter.html index 19a7cdefe..563c6cfae 100644 --- a/docs/adapter.html +++ b/docs/adapter.html @@ -133,7 +133,7 @@ Object.assig x => x + 3, async x => (await x) + 4 ); -(async() => { +(async () => { console.log(await sum(5)); // 15 (after one second) })();
Performs left-to-right function composition.
Use Array.prototype.reduce() with the spread operator (...) to perform left-to-right function composition. The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args))); diff --git a/docs/index.html b/docs/index.html index 4b119a1d3..77052edad 100644 --- a/docs/index.html +++ b/docs/index.html @@ -410,9 +410,9 @@
Removes elements from an array for which the given function returns false.
Use Array.prototype.filter() to find array elements that return truthy values and Array.prototype.reduce() to remove elements using Array.prototype.splice(). The func is invoked with three arguments (value, index, array).
const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : [];
remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]
Returns a random element from an array.
Use Math.random() to generate a random number, multiply it by length and round it off to the nearest whole number using Math.floor(). This method also works with strings.
const sample = arr => arr[Math.floor(Math.random() * arr.length)]; diff --git a/snippets/pipeAsyncFunctions.md b/snippets/pipeAsyncFunctions.md index 47d6f620c..8c93add3b 100644 --- a/snippets/pipeAsyncFunctions.md +++ b/snippets/pipeAsyncFunctions.md @@ -17,7 +17,7 @@ const sum = pipeAsyncFunctions( x => x + 3, async x => (await x) + 4 ); -(async() => { +(async () => { console.log(await sum(5)); // 15 (after one second) })(); ``` diff --git a/snippets/remove.md b/snippets/remove.md index 58de9c2e0..a8c472774 100644 --- a/snippets/remove.md +++ b/snippets/remove.md @@ -9,9 +9,9 @@ The `func` is invoked with three arguments (`value, index, array`). const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; ``` diff --git a/test/_30s.js b/test/_30s.js index 4dece075b..b5d57f74d 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -988,9 +988,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args)); const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); const renameKeys = (keysMap, obj) =>