From 9fbb61c79c4e82f9db729e2fa79d43dfe7712546 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Mon, 18 Mar 2019 06:32:40 +0000 Subject: [PATCH] Travis build: 1068 --- README.md | 50 ++++++++++++++++------------------ docs/adapter.html | 5 ++-- docs/function.html | 28 +++++++++---------- docs/index.html | 9 +++--- docs/math.html | 4 +-- docs/object.html | 6 ++-- snippets/checkProp.md | 1 + snippets/dig.md | 6 ++-- snippets/factorial.md | 4 +-- snippets/pipeAsyncFunctions.md | 3 +- snippets/remove.md | 7 ++--- test/_30s.js | 17 ++++++------ 12 files changed, 67 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 8e46b49ab..2a5531dc5 100644 --- a/README.md +++ b/README.md @@ -671,14 +671,13 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr Examples ```js - const sum = pipeAsyncFunctions( x => x + 1, x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)), x => x + 3, async x => (await x) + 4 ); -(async() => { +(async () => { console.log(await sum(5)); // 15 (after one second) })(); ``` @@ -2320,13 +2319,12 @@ Use `Array.prototype.filter()` to find array elements that return truthy values The `func` is invoked with three arguments (`value, index, array`). ```js - 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); + }, []) : []; ``` @@ -4656,9 +4654,9 @@ chainAsync([ ### checkProp -Given a `predicate` function and a `prop` string this curried function will then take an `object` to inspect by calling the property and passing it to the predicate. +Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate. -It summons `prop` on `obj` and passes it to a provided `predicate` function and returns a masked boolean +Summon `prop` on `obj`, pass it to a provided `predicate` function and return a masked boolean. ```js const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); @@ -4669,23 +4667,23 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); ```js -const lengthIs4 = checkProp(l => l === 4, 'length') -lengthIs4([]) // false -lengthIs4([1,2,3,4]) // true -lengthIs4(new Set([1,2,3,4])) // false (Set uses Size, not length) +const lengthIs4 = checkProp(l => l === 4, 'length'); +lengthIs4([]); // false +lengthIs4([1,2,3,4]); // true +lengthIs4(new Set([1,2,3,4])); // false (Set uses Size, not length) -const session = { user: {} } -const validUserSession = checkProps(u => u.active && !u.disabled, 'user') +const session = { user: {} }; +const validUserSession = checkProps(u => u.active && !u.disabled, 'user'); -validUserSession(session) // false +validUserSession(session); // false -session.user.active = true -validUserSession(session) // true +session.user.active = true; +validUserSession(session); // true -const noLength(l => l === undefined, 'length') -noLength([]) // false -noLength({}) // true -noLength(new Set()) // true +const noLength(l => l === undefined, 'length'); +noLength([]); // false +noLength({}); // true +noLength(new Set()); // true ``` @@ -5545,8 +5543,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); @@ -6928,9 +6926,9 @@ const dig = (obj, target) => target in obj ? obj[target] : Object.values(obj).reduce((acc, val) => { - if (acc !== undefined) return acc; - if (typeof val === 'object') return dig(val, target); - }, undefined); + if (acc !== undefined) return acc; + if (typeof val === 'object') return dig(val, target); + }, undefined); ```
diff --git a/docs/adapter.html b/docs/adapter.html index 7ba7b9ee8..e37c5c2b0 100644 --- a/docs/adapter.html +++ b/docs/adapter.html @@ -127,14 +127,13 @@ Object.assig const fn = overArgs((x, y) => [x, y], [square, double]); fn(9, 3); // [81, 6]

pipeAsyncFunctions

Performs left-to-right function composition for asynchronous functions.

Use Array.prototype.reduce() with the spread operator (...) to perform left-to-right function composition using Promise.then(). The functions can return a combination of: simple values, Promise's, or they can be defined as async ones returning through await. All functions must be unary.

const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
-
-const sum = pipeAsyncFunctions(
+
const sum = pipeAsyncFunctions(
   x => x + 1,
   x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
   x => x + 3,
   async x => (await x) + 4
 );
-(async() => {
+(async () => {
   console.log(await sum(5)); // 15 (after one second)
 })();
 

Recommended Resource - ES6: The Right Parts

Learn new ES6 JavaScript language features like arrow function, destructuring, generators & more to write cleaner and more productive, readable programs.

pipeFunctions

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/function.html b/docs/function.html
index 3c480027b..f31c958df 100644
--- a/docs/function.html
+++ b/docs/function.html
@@ -143,25 +143,25 @@ console.log<
     console.log('2 second');
   }
 ]);
-

checkProp

Given a predicate function and a prop string this curried function will then take an object to inspect by calling the property and passing it to the predicate.

It summons prop on obj and passes it to a provided predicate function and returns a masked boolean

const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
+

checkProp

Given a predicate function and a prop string, this curried function will then take an object to inspect by calling the property and passing it to the predicate.

Summon prop on obj, pass it to a provided predicate function and return a masked boolean.

const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
 
-const lengthIs4 = checkProp(l => l === 4, 'length')
-lengthIs4([]) // false
-lengthIs4([1,2,3,4]) // true
-lengthIs4(new Set([1,2,3,4])) // false (Set uses Size, not length)
+const lengthIs4 = checkProp(l => l === 4, 'length');
+lengthIs4([]); // false
+lengthIs4([1,2,3,4]); // true
+lengthIs4(new Set([1,2,3,4])); // false (Set uses Size, not length)
 
-const session = { user: {} }
-const validUserSession = checkProps(u => u.active && !u.disabled, 'user')
+const session = { user: {} };
+const validUserSession = checkProps(u => u.active && !u.disabled, 'user');
 
-validUserSession(session) // false
+validUserSession(session); // false
 
-session.user.active = true
-validUserSession(session) // true
+session.user.active = true;
+validUserSession(session); // true
 
-const noLength(l => l === undefined, 'length')
-noLength([]) // false
-noLength({}) // true
-noLength(new Set()) // true
+const noLength(l => l === undefined, 'length');
+noLength([]); // false
+noLength({}); // true
+noLength(new Set()); // true
 

compose

Performs right-to-left function composition.

Use Array.prototype.reduce() to perform right-to-left function composition. The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.

const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
 
const add5 = x => x + 5;
 const multiply = (x, y) => x * y;
diff --git a/docs/index.html b/docs/index.html
index d0831fb2c..623c127c7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -407,13 +407,12 @@
 

reject

Takes a predicate and array, like Array.prototype.filter(), but only keeps x if pred(x) === false.

const reject = (pred, array) => array.filter((...args) => !pred(...args));
 
reject(x => x % 2 === 0, [1, 2, 3, 4, 5]); // [1, 3, 5]
 reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']); // ['Pear', 'Kiwi']
-

remove

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) =>
+

remove

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]
 

sample

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 c2d3809b0..ead5659f6 100644
--- a/docs/math.html
+++ b/docs/math.html
@@ -152,8 +152,8 @@ own individual rating by supplying it as the third argument.
 

factorial

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/docs/object.html b/docs/object.html
index 676731b44..91405896b 100644
--- a/docs/object.html
+++ b/docs/object.html
@@ -178,9 +178,9 @@ o[1in obj
     ? obj[target]
     : Object.values(obj).reduce((acc, val) => {
-        if (acc !== undefined) return acc;
-        if (typeof val === 'object') return dig(val, target);
-      }, undefined);
+      if (acc !== undefined) return acc;
+      if (typeof val === 'object') return dig(val, target);
+    }, undefined);
 
const data = {
   level1: {
     level2: {
diff --git a/snippets/checkProp.md b/snippets/checkProp.md
index b0c5c8df8..c90195730 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -9,6 +9,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
 ```
 
 ```js
+
 const lengthIs4 = checkProp(l => l === 4, 'length');
 lengthIs4([]); // false
 lengthIs4([1,2,3,4]); // true
diff --git a/snippets/dig.md b/snippets/dig.md
index c97559833..737130b6e 100644
--- a/snippets/dig.md
+++ b/snippets/dig.md
@@ -10,9 +10,9 @@ const dig = (obj, target) =>
   target in obj
     ? obj[target]
     : Object.values(obj).reduce((acc, val) => {
-        if (acc !== undefined) return acc;
-        if (typeof val === 'object') return dig(val, target);
-      }, undefined);
+      if (acc !== undefined) return acc;
+      if (typeof val === 'object') return dig(val, target);
+    }, undefined);
 ```
 
 ```js
diff --git a/snippets/factorial.md b/snippets/factorial.md
index 86ebe69b6..cf3acc9cc 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 61b850a39..8c93add3b 100644
--- a/snippets/pipeAsyncFunctions.md
+++ b/snippets/pipeAsyncFunctions.md
@@ -11,14 +11,13 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr
 ```
 
 ```js
-
 const sum = pipeAsyncFunctions(
   x => x + 1,
   x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
   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 1c457d2d9..a8c472774 100644
--- a/snippets/remove.md
+++ b/snippets/remove.md
@@ -6,13 +6,12 @@ Use `Array.prototype.filter()` to find array elements that return truthy values
 The `func` is invoked with three arguments (`value, index, array`).
 
 ```js
-
 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 36a3ea263..bc92b61ee 100644
--- a/test/_30s.js
+++ b/test/_30s.js
@@ -268,9 +268,9 @@ const dig = (obj, target) =>
   target in obj
     ? obj[target]
     : Object.values(obj).reduce((acc, val) => {
-        if (acc !== undefined) return acc;
-        if (typeof val === 'object') return dig(val, target);
-      }, undefined);
+      if (acc !== undefined) return acc;
+      if (typeof val === 'object') return dig(val, target);
+    }, undefined);
 const digitize = n => [...`${n}`].map(i => parseInt(i));
 const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
 const drop = (arr, n = 1) => arr.slice(n);
@@ -342,8 +342,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);
@@ -988,13 +988,12 @@ const reducedFilter = (data, keys, fn) =>
     }, {})
   );
 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) =>