From 0d667e61839cf68b7f42091da49d25116b181257 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 22 Aug 2019 07:37:04 +0000 Subject: [PATCH] Travis build: 1386 --- README.md | 34 +++++++++++++------------- snippets/checkProp.md | 1 + snippets/deepClone.md | 5 ++-- snippets/deepMapKeys.md | 5 ++-- snippets/dig.md | 7 +++--- snippets/factorial.md | 9 +++---- snippets/getMeridiemSuffixOfInteger.md | 9 +++---- snippets/join.md | 5 ++-- test/_30s.js | 34 +++++++++++++------------- 9 files changed, 52 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index a4d8b9770..f6844bc8d 100644 --- a/README.md +++ b/README.md @@ -1722,8 +1722,8 @@ const join = (arr, separator = ',', end = separator) => i === arr.length - 2 ? acc + val + end : i === arr.length - 1 - ? acc + val - : acc + val + separator, + ? acc + val + : acc + val + separator, '' ); ``` @@ -4269,10 +4269,10 @@ const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 - ? 12 + 'pm' - : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? 12 + 'pm' + : num < 12 + ? (num % 12) + 'am' + : (num % 12) + 'pm'; ```
@@ -5484,11 +5484,11 @@ 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); + ? 1 + : n * factorial(n - 1); ```
@@ -6676,8 +6676,8 @@ const deepClone = obj => { return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) - ? Array.from(obj) - : clone; + ? Array.from(obj) + : clone; }; ``` @@ -6765,13 +6765,13 @@ const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) : typeof obj === 'object' - ? Object.keys(obj).reduce((acc, current) => { + ? Object.keys(obj).reduce((acc, current) => { const val = obj[current]; acc[f(current)] = val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val); return acc; }, {}) - : obj; + : obj; ```
@@ -6842,9 +6842,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/snippets/checkProp.md b/snippets/checkProp.md index fd2eb7cfb..58d5b655e 100644 --- a/snippets/checkProp.md +++ b/snippets/checkProp.md @@ -15,6 +15,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/snippets/deepClone.md b/snippets/deepClone.md index ab933ae46..c2f4755c5 100644 --- a/snippets/deepClone.md +++ b/snippets/deepClone.md @@ -10,7 +10,6 @@ Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of th Use `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned. ```js - const deepClone = obj => { let clone = Object.assign({}, obj); Object.keys(clone).forEach( @@ -19,8 +18,8 @@ const deepClone = obj => { return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) - ? Array.from(obj) - : clone; + ? Array.from(obj) + : clone; }; ``` diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md index 349ba652f..e07084847 100644 --- a/snippets/deepMapKeys.md +++ b/snippets/deepMapKeys.md @@ -10,18 +10,17 @@ 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)) : typeof obj === 'object' - ? Object.keys(obj).reduce((acc, current) => { + ? Object.keys(obj).reduce((acc, current) => { const val = obj[current]; acc[f(current)] = val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val); return acc; }, {}) - : obj; + : obj; ``` ```js diff --git a/snippets/dig.md b/snippets/dig.md index b1ec83f8e..16c08bebe 100644 --- a/snippets/dig.md +++ b/snippets/dig.md @@ -9,14 +9,13 @@ 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] : 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 baa668b8f..0b1413c15 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -11,15 +11,14 @@ 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 ? (() => { - throw new TypeError('Negative numbers are not allowed!'); - })() + throw new TypeError('Negative numbers are not allowed!'); + })() : n <= 1 - ? 1 - : n * factorial(n - 1); + ? 1 + : n * factorial(n - 1); ``` ```js diff --git a/snippets/getMeridiemSuffixOfInteger.md b/snippets/getMeridiemSuffixOfInteger.md index 74ac86ec7..c460f5644 100644 --- a/snippets/getMeridiemSuffixOfInteger.md +++ b/snippets/getMeridiemSuffixOfInteger.md @@ -8,15 +8,14 @@ Converts an integer to a suffixed string, adding `am` or `pm` based on its value Use the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix. ```js - const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 - ? 12 + 'pm' - : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? 12 + 'pm' + : num < 12 + ? (num % 12) + 'am' + : (num % 12) + 'pm'; ``` ```js diff --git a/snippets/join.md b/snippets/join.md index 6bf258224..6df3c9145 100644 --- a/snippets/join.md +++ b/snippets/join.md @@ -11,15 +11,14 @@ Omit the second argument, `separator`, to use a default separator of `','`. Omit the third argument, `end`, to use the same value as `separator` by default. ```js - const join = (arr, separator = ',', end = separator) => arr.reduce( (acc, val, i) => i === arr.length - 2 ? acc + val + end : i === arr.length - 1 - ? acc + val - : acc + val + separator, + ? acc + val + : acc + val + separator, '' ); ``` diff --git a/test/_30s.js b/test/_30s.js index 607a5f691..1b9033f7a 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -198,8 +198,8 @@ const deepClone = obj => { return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) - ? Array.from(obj) - : clone; + ? Array.from(obj) + : clone; }; const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFlatten(v) : v))); const deepFreeze = obj => @@ -211,13 +211,13 @@ const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) : typeof obj === 'object' - ? Object.keys(obj).reduce((acc, current) => { + ? Object.keys(obj).reduce((acc, current) => { const val = obj[current]; acc[f(current)] = val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val); return acc; }, {}) - : obj; + : obj; const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj); const defer = (fn, ...args) => setTimeout(fn, 1, ...args); const degreesToRads = deg => (deg * Math.PI) / 180.0; @@ -239,9 +239,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); @@ -314,11 +314,11 @@ 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); + ? 1 + : n * factorial(n - 1); const fibonacci = n => Array.from({ length: n }).reduce( (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), @@ -419,10 +419,10 @@ const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 - ? 12 + 'pm' - : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? 12 + 'pm' + : num < 12 + ? (num % 12) + 'am' + : (num % 12) + 'pm'; const getScrollPosition = (el = window) => ({ x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft, y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop @@ -643,8 +643,8 @@ const join = (arr, separator = ',', end = separator) => i === arr.length - 2 ? acc + val + end : i === arr.length - 1 - ? acc + val - : acc + val + separator, + ? acc + val + : acc + val + separator, '' ); const JSONtoCSV = (arr, columns, delimiter = ',') =>