From b25e9f87a0c8c40d5f2e4ba152f640635e74cad5 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 12 Dec 2018 17:17:27 +0000 Subject: [PATCH] Travis build: 891 --- README.md | 11 ++++------- docs/adapter.html | 2 +- docs/index.html | 6 +++--- docs/math.html | 3 +-- docs/object.html | 6 ++---- snippets/deepMapKeys.md | 1 - snippets/dig.md | 1 - snippets/factorial.md | 1 - snippets/pipeAsyncFunctions.md | 2 +- snippets/remove.md | 6 +++--- test/_30s.js | 9 +++------ 11 files changed, 18 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index e96ff2f5a..be4d6ab5d 100644 --- a/README.md +++ b/README.md @@ -670,7 +670,7 @@ const sum = pipeAsyncFunctions( x => x + 3, async x => (await x) + 4 ); -(async () => { +(async() => { console.log(await sum(5)); // 15 (after one second) })(); ``` @@ -2315,9 +2315,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); + }, []) : []; ``` @@ -5490,7 +5490,6 @@ Otherwise, return the product of `n` and the factorial of `n - 1`. Throws an exception if `n` is a negative number. ```js - const factorial = n => n < 0 ? (() => { @@ -6719,7 +6718,6 @@ Use `Object.keys(obj)` to iterate over the object's keys. Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`. ```js - const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) @@ -6799,7 +6797,6 @@ Use the `in` operator to check if `target` exists in `obj`. If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found. ```js - const dig = (obj, target) => target in obj ? obj[target] diff --git a/docs/adapter.html b/docs/adapter.html index 9b853af6c..d2314ae49 100644 --- a/docs/adapter.html +++ b/docs/adapter.html @@ -131,7 +131,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 778ab9167..54e8f4df0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -408,9 +408,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 cc23b5dd0..565c52a73 100644 --- a/docs/math.html +++ b/docs/math.html @@ -147,8 +147,7 @@ For teams, each rating can adjusted based on own team's average rating vs. average rating of opposing team, with the score being added to their 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 => +
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!'); diff --git a/docs/object.html b/docs/object.html index 2da14cf97..d7200d5c0 100644 --- a/docs/object.html +++ b/docs/object.html @@ -128,8 +128,7 @@ o[0] = 3; // not allowed o[1][0] = 4; // not allowed as well -
Deep maps an object keys.
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use Object.keys(obj) to iterate over the object's keys. Use Array.prototype.reduce() to create a new object with the same values and mapped keys using fn.
-const deepMapKeys = (obj, f) => +
Deep maps an object keys.
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use Object.keys(obj) to iterate over the object's keys. Use Array.prototype.reduce() to create a new object with the same values and mapped keys using fn.
const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) : typeof obj === 'object' @@ -169,8 +168,7 @@ o[1
Assigns default values for all properties in an object that are undefined.
Use Object.assign() to create a new empty object and copy the original one to maintain key order, use Array.prototype.reverse() and the spread operator ... to combine the default values from left to right, finally use obj again to overwrite properties that originally had a value.
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 } -
Returns the target value in a nested JSON object, based on the given key.
Use the in operator to check if target exists in obj. If found, return the value of obj[target], otherwise use Object.values(obj) and Array.prototype.reduce() to recursively call dig on each nested object until the first matching key/value pair is found.
-const dig = (obj, target) => +
Returns the target value in a nested JSON object, based on the given key.
Use the in operator to check if target exists in obj. If found, return the value of obj[target], otherwise use Object.values(obj) and Array.prototype.reduce() to recursively call dig on each nested object until the first matching key/value pair is found.
const dig = (obj, target) => target in obj ? obj[target] : Object.values(obj).reduce((acc, val) => { diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md index e0223cb81..c736420ee 100644 --- a/snippets/deepMapKeys.md +++ b/snippets/deepMapKeys.md @@ -8,7 +8,6 @@ Use `Object.keys(obj)` to iterate over the object's keys. Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`. ```js - const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) diff --git a/snippets/dig.md b/snippets/dig.md index a349ef2d3..737130b6e 100644 --- a/snippets/dig.md +++ b/snippets/dig.md @@ -6,7 +6,6 @@ Use the `in` operator to check if `target` exists in `obj`. If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found. ```js - const dig = (obj, target) => target in obj ? obj[target] diff --git a/snippets/factorial.md b/snippets/factorial.md index 2266247b4..cf3acc9cc 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -8,7 +8,6 @@ Otherwise, return the product of `n` and the factorial of `n - 1`. Throws an exception if `n` is a negative number. ```js - const factorial = n => n < 0 ? (() => { diff --git a/snippets/pipeAsyncFunctions.md b/snippets/pipeAsyncFunctions.md index 8c93add3b..47d6f620c 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 a8c472774..58de9c2e0 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 827bb4978..29a905d6c 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -224,7 +224,6 @@ const deepFreeze = obj => prop => !(obj[prop] instanceof Object) || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop]) ) || Object.freeze(obj); - const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) @@ -253,7 +252,6 @@ const differenceBy = (a, b, fn) => { return a.filter(x => !s.has(fn(x))); }; const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => comp(a, b)) === -1); - const dig = (obj, target) => target in obj ? obj[target] @@ -329,7 +327,6 @@ const extendHex = shortHex => .split('') .map(x => x + x) .join(''); - const factorial = n => n < 0 ? (() => { @@ -980,9 +977,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) =>