From 08c9806c7221d29845b0c129c1ffc69af920a22e Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Tue, 5 Mar 2019 18:13:20 +0000
Subject: [PATCH] Travis build: 1043
---
README.md | 20 ++++++++++----------
docs/adapter.html | 2 +-
docs/index.html | 14 +++++++-------
docs/math.html | 4 ++--
snippets/factorial.md | 4 ++--
snippets/pipeAsyncFunctions.md | 2 +-
snippets/remove.md | 6 +++---
test/_30s.js | 12 ++++++------
8 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/README.md b/README.md
index e5ef8965e..de995c6ce 100644
--- a/README.md
+++ b/README.md
@@ -676,7 +676,7 @@ const sum = pipeAsyncFunctions(
x => x + 3,
async x => (await x) + 4
);
-(async() => {
+(async () => {
console.log(await sum(5)); // 15 (after one second)
})();
```
@@ -1096,12 +1096,12 @@ difference([1, 2, 3], [1, 2, 4]); // [3]
Returns the difference between two arrays, after applying the provided function to each array element of both.
-Create a `Set` by applying `fn` to each element in `b`, then use `Array.prototype.filter()` in combination with `fn` on `a` to only keep values not contained in the previously created set.
+Create a `Set` by applying `fn` to each element in `b`, then use `Array.prototype.map()` to apply `fn` to each element in `a`, then `Array.prototype.filter()`
```js
const differenceBy = (a, b, fn) => {
const s = new Set(b.map(fn));
- return a.filter(x => !s.has(fn(x)));
+ return a.map(fn).filter(el => !s.has(el));
};
```
@@ -1109,8 +1109,8 @@ const differenceBy = (a, b, fn) => {
Learn new ES6 JavaScript language features like arrow function, destructuring, generators & more to write cleaner and more productive, readable programs.
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 b2a9ca352..4197de212 100644 --- a/docs/index.html +++ b/docs/index.html @@ -135,12 +135,12 @@ return a.filter(x => !s.has(x)); };
difference([1, 2, 3], [1, 2, 4]); // [3] -
Returns the difference between two arrays, after applying the provided function to each array element of both.
Create a Set by applying fn to each element in b, then use Array.prototype.filter() in combination with fn on a to only keep values not contained in the previously created set.
const differenceBy = (a, b, fn) => { +
Returns the difference between two arrays, after applying the provided function to each array element of both.
Create a Set by applying fn to each element in b, then use Array.prototype.map() to apply fn to each element in a, then Array.prototype.filter()
const differenceBy = (a, b, fn) => { const s = new Set(b.map(fn)); - return a.filter(x => !s.has(fn(x))); + return a.map(fn).filter(el => !s.has(el)); }; -
differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2] -differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [ { x: 2 } ] +
differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1] +differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [2]
Filters out all values from an array for which the comparator function does not return true.
Use Array.prototype.filter() and Array.prototype.findIndex() to find the appropriate values.
const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1);
differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2]
Returns a new array with n elements removed from the left.
Use Array.prototype.slice() to slice the remove the specified number of elements from the left.
const drop = (arr, n = 1) => arr.slice(n); @@ -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/docs/math.html b/docs/math.html index ea60b10ff..94c8388f7 100644 --- a/docs/math.html +++ b/docs/math.html @@ -152,8 +152,8 @@ own individual rating by supplying it as the third argument.
Calculates the factorial of a number.
Use recursion. If n is less than or equal to 1, return 1. Otherwise, return the product of n and the factorial of n - 1. Throws an exception if n is a negative number.
const factorial = n => n < 0 ? (() => { - throw new TypeError('Negative numbers are not allowed!'); - })() + throw new TypeError('Negative numbers are not allowed!'); + })() : n <= 1 ? 1 : n * factorial(n - 1); diff --git a/snippets/factorial.md b/snippets/factorial.md index cf3acc9cc..86ebe69b6 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -11,8 +11,8 @@ Throws an exception if `n` is a negative number. const factorial = n => n < 0 ? (() => { - throw new TypeError('Negative numbers are not allowed!'); - })() + throw new TypeError('Negative numbers are not allowed!'); + })() : n <= 1 ? 1 : n * factorial(n - 1); 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 ad3b141de..117a62318 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -260,7 +260,7 @@ const difference = (a, b) => { }; const differenceBy = (a, b, fn) => { const s = new Set(b.map(fn)); - return a.filter(x => !s.has(fn(x))); + return a.map(fn).filter(el => !s.has(el)); }; const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1); const dig = (obj, target) => @@ -341,8 +341,8 @@ const extendHex = shortHex => const factorial = n => n < 0 ? (() => { - throw new TypeError('Negative numbers are not allowed!'); - })() + throw new TypeError('Negative numbers are not allowed!'); + })() : n <= 1 ? 1 : n * factorial(n - 1); @@ -990,9 +990,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) =>