From 16ade9e8400703c4ee9718f1ee84238b5a1f688c Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Fri, 7 Jun 2019 15:03:12 +0000 Subject: [PATCH] Travis build: 1221 --- README.md | 31 ++++++++++++++++--------------- docs/adapter.html | 2 +- docs/function.html | 1 + docs/index.html | 8 ++++---- docs/math.html | 4 ++-- docs/object.html | 14 +++++++------- snippets/checkProp.md | 1 + snippets/deepMapKeys.md | 8 ++++---- snippets/dig.md | 6 +++--- snippets/factorial.md | 4 ++-- snippets/pipeAsyncFunctions.md | 2 +- snippets/remove.md | 6 +++--- test/_30s.js | 24 ++++++++++++------------ 13 files changed, 57 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 0fb47451b..5d8948098 100644 --- a/README.md +++ b/README.md @@ -678,7 +678,7 @@ const sum = pipeAsyncFunctions( x => x + 3, async x => (await x) + 4 ); -(async () => { +(async() => { console.log(await sum(5)); // 15 (after one second) })(); ``` @@ -2328,9 +2328,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); + }, []) : []; ``` @@ -2976,9 +2976,9 @@ uniqueElementsBy( ### uniqueElementsByRight -Returns all unique values of an array, based on a provided comparator function. +Returns all unique values of an array, based on a provided comparator function, starting from the right. -Use `Array.prototype.reduce()` and `Array.prototype.some()` for an array containing only the last unique occurrence of each value, based on the comparator function, `fn`. +Use `Array.prototype.reduceRight()` and `Array.prototype.some()` for an array containing only the last unique occurrence of each value, based on the comparator function, `fn`. The comparator function takes two arguments: the values of the two elements being compared. ```js @@ -4745,6 +4745,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false @@ -5622,8 +5623,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); @@ -6960,11 +6961,11 @@ const deepMapKeys = (obj, f) => ? obj.map(val => deepMapKeys(val, f)) : typeof obj === 'object' ? Object.keys(obj).reduce((acc, current) => { - const val = obj[current]; - acc[f(current)] = + const val = obj[current]; + acc[f(current)] = val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val); - return acc; - }, {}) + return acc; + }, {}) : obj; ``` @@ -7038,9 +7039,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 374eeda4d..54ecf67c8 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) })();

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 69d080d4c..108886ee3 100644
--- a/docs/function.html
+++ b/docs/function.html
@@ -164,6 +164,7 @@ console.log<
 
 
 
+
 const lengthIs4 = checkProp(l => l === 4, 'length');
 lengthIs4([]); // false
 lengthIs4([1,2,3,4]); // true
diff --git a/docs/index.html b/docs/index.html
index c01cbccdc..f73e97e61 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -414,9 +414,9 @@
 

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)];
@@ -574,7 +574,7 @@ managers; //
   ],
   (a, b) => a.id == b.id
 ); // [ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]
-

uniqueElementsByRight

Returns all unique values of an array, based on a provided comparator function.

Use Array.prototype.reduce() and Array.prototype.some() for an array containing only the last unique occurrence of each value, based on the comparator function, fn. The comparator function takes two arguments: the values of the two elements being compared.

const uniqueElementsByRight = (arr, fn) =>
+

uniqueElementsByRight

Returns all unique values of an array, based on a provided comparator function, starting from the right.

Use Array.prototype.reduceRight() and Array.prototype.some() for an array containing only the last unique occurrence of each value, based on the comparator function, fn. The comparator function takes two arguments: the values of the two elements being compared.

const uniqueElementsByRight = (arr, fn) =>
   arr.reduceRight((acc, v) => {
     if (!acc.some(x => fn(v, x))) acc.push(v);
     return acc;
diff --git a/docs/math.html b/docs/math.html
index 2313fb419..89fafd2de 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 20f939411..243a0d0c1 100644
--- a/docs/object.html
+++ b/docs/object.html
@@ -151,11 +151,11 @@ o[1? obj.map(val => deepMapKeys(val, f))
     : typeof obj === 'object'
       ? Object.keys(obj).reduce((acc, current) => {
-          const val = obj[current];
-          acc[f(current)] =
+        const val = obj[current];
+        acc[f(current)] =
             val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
-          return acc;
-        }, {})
+        return acc;
+      }, {})
       : obj;
 
const obj = {
   foo: '1',
@@ -190,9 +190,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 235a43028..1e0ed30d5 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -28,6 +28,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
 
 
 
+
 
 const lengthIs4 = checkProp(l => l === 4, 'length');
 lengthIs4([]); // false
diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md
index 970453bdc..c736420ee 100644
--- a/snippets/deepMapKeys.md
+++ b/snippets/deepMapKeys.md
@@ -13,11 +13,11 @@ const deepMapKeys = (obj, f) =>
     ? obj.map(val => deepMapKeys(val, f))
     : typeof obj === 'object'
       ? Object.keys(obj).reduce((acc, current) => {
-          const val = obj[current];
-          acc[f(current)] =
+        const val = obj[current];
+        acc[f(current)] =
             val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
-          return acc;
-        }, {})
+        return acc;
+      }, {})
       : obj;
 ```
 
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 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 813af8160..2c0a2ba21 100644
--- a/test/_30s.js
+++ b/test/_30s.js
@@ -245,11 +245,11 @@ const deepMapKeys = (obj, f) =>
     ? obj.map(val => deepMapKeys(val, f))
     : typeof obj === 'object'
       ? Object.keys(obj).reduce((acc, current) => {
-          const val = obj[current];
-          acc[f(current)] =
+        const val = obj[current];
+        acc[f(current)] =
             val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
-          return acc;
-        }, {})
+        return acc;
+      }, {})
       : obj;
 const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
 const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
@@ -272,9 +272,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);
@@ -347,8 +347,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);
@@ -1004,9 +1004,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) =>