Travis build: 872 [cron]

This commit is contained in:
30secondsofcode
2018-12-08 14:30:17 +00:00
parent 17972d4574
commit 5b3d2fb301
9 changed files with 2217 additions and 2103 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

64
dist/_30s.es5.js vendored
View File

@ -754,6 +754,9 @@
return acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i); return acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i);
}, []); }, []);
}; };
var filterFalsy = function filterFalsy(arr) {
return arr.filter(Boolean);
};
var filterNonUnique = function filterNonUnique(arr) { var filterNonUnique = function filterNonUnique(arr) {
return arr.filter(function (i) { return arr.filter(function (i) {
return arr.indexOf(i) === arr.lastIndexOf(i); return arr.indexOf(i) === arr.lastIndexOf(i);
@ -1427,6 +1430,17 @@
}, {}); }, {});
}, {}); }, {});
}; };
var midpoint = function midpoint(_ref13, _ref14) {
var _ref15 = _slicedToArray(_ref13, 2),
x1 = _ref15[0],
y1 = _ref15[1];
var _ref16 = _slicedToArray(_ref14, 2),
x2 = _ref16[0],
y2 = _ref16[1];
return [(x1 + x2) / 2, (y1 + y2) / 2];
};
var minBy = function minBy(arr, fn) { var minBy = function minBy(arr, fn) {
return Math.min.apply(Math, _toConsumableArray(arr.map(typeof fn === 'function' ? fn : function (val) { return Math.min.apply(Math, _toConsumableArray(arr.map(typeof fn === 'function' ? fn : function (val) {
return val[fn]; return val[fn];
@ -1497,10 +1511,10 @@
return (n === -1 ? arr.slice(n) : arr.slice(n, n + 1))[0]; return (n === -1 ? arr.slice(n) : arr.slice(n, n + 1))[0];
}; };
var objectFromPairs = function objectFromPairs(arr) { var objectFromPairs = function objectFromPairs(arr) {
return arr.reduce(function (a, _ref13) { return arr.reduce(function (a, _ref17) {
var _ref14 = _slicedToArray(_ref13, 2), var _ref18 = _slicedToArray(_ref17, 2),
key = _ref14[0], key = _ref18[0],
val = _ref14[1]; val = _ref18[1];
return a[key] = val, a; return a[key] = val, a;
}, {}); }, {});
@ -1589,10 +1603,10 @@
return _toConsumableArray(arr).sort(function (a, b) { return _toConsumableArray(arr).sort(function (a, b) {
return props.reduce(function (acc, prop, i) { return props.reduce(function (acc, prop, i) {
if (acc === 0) { if (acc === 0) {
var _ref15 = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]], var _ref19 = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
_ref16 = _slicedToArray(_ref15, 2), _ref20 = _slicedToArray(_ref19, 2),
p1 = _ref16[0], p1 = _ref20[0],
p2 = _ref16[1]; p2 = _ref20[1];
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
} }
@ -1970,8 +1984,8 @@
type: 'application/javascript; charset=utf-8' type: 'application/javascript; charset=utf-8'
})); }));
return new Promise(function (res, rej) { return new Promise(function (res, rej) {
worker.onmessage = function (_ref17) { worker.onmessage = function (_ref21) {
var data = _ref17.data; var data = _ref21.data;
res(data), worker.terminate(); res(data), worker.terminate();
}; };
@ -1988,18 +2002,18 @@
var sample = function sample(arr) { var sample = function sample(arr) {
return arr[Math.floor(Math.random() * arr.length)]; return arr[Math.floor(Math.random() * arr.length)];
}; };
var sampleSize = function sampleSize(_ref18) { var sampleSize = function sampleSize(_ref22) {
var _ref19 = _toArray(_ref18), var _ref23 = _toArray(_ref22),
arr = _ref19.slice(0); arr = _ref23.slice(0);
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var m = arr.length; var m = arr.length;
while (m) { while (m) {
var i = Math.floor(Math.random() * m--); var i = Math.floor(Math.random() * m--);
var _ref20 = [arr[i], arr[m]]; var _ref24 = [arr[i], arr[m]];
arr[m] = _ref20[0]; arr[m] = _ref24[0];
arr[i] = _ref20[1]; arr[i] = _ref24[1];
} }
return arr.slice(0, n); return arr.slice(0, n);
@ -2046,17 +2060,17 @@
return e.style.display = ''; return e.style.display = '';
}); });
}; };
var shuffle = function shuffle(_ref21) { var shuffle = function shuffle(_ref25) {
var _ref22 = _toArray(_ref21), var _ref26 = _toArray(_ref25),
arr = _ref22.slice(0); arr = _ref26.slice(0);
var m = arr.length; var m = arr.length;
while (m) { while (m) {
var i = Math.floor(Math.random() * m--); var i = Math.floor(Math.random() * m--);
var _ref23 = [arr[i], arr[m]]; var _ref27 = [arr[i], arr[m]];
arr[m] = _ref23[0]; arr[m] = _ref27[0];
arr[i] = _ref23[1]; arr[i] = _ref27[1];
} }
return arr; return arr;
@ -2130,8 +2144,8 @@
}; };
}).sort(function (a, b) { }).sort(function (a, b) {
return compare(a.item, b.item) || a.index - b.index; return compare(a.item, b.item) || a.index - b.index;
}).map(function (_ref24) { }).map(function (_ref28) {
var item = _ref24.item; var item = _ref28.item;
return item; return item;
}); });
}; };
@ -2656,6 +2670,7 @@
exports.extendHex = extendHex; exports.extendHex = extendHex;
exports.factorial = factorial; exports.factorial = factorial;
exports.fibonacci = fibonacci; exports.fibonacci = fibonacci;
exports.filterFalsy = filterFalsy;
exports.filterNonUnique = filterNonUnique; exports.filterNonUnique = filterNonUnique;
exports.filterNonUniqueBy = filterNonUniqueBy; exports.filterNonUniqueBy = filterNonUniqueBy;
exports.findKey = findKey; exports.findKey = findKey;
@ -2766,6 +2781,7 @@
exports.median = median; exports.median = median;
exports.memoize = memoize; exports.memoize = memoize;
exports.merge = merge; exports.merge = merge;
exports.midpoint = midpoint;
exports.minBy = minBy; exports.minBy = minBy;
exports.minDate = minDate; exports.minDate = minDate;
exports.minN = minN; exports.minN = minN;

File diff suppressed because one or more lines are too long

10
dist/_30s.esm.js vendored
View File

@ -327,6 +327,7 @@ const fibonacci = n =>
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[] []
); );
const filterFalsy = arr => arr.filter(Boolean);
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i)); const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
const filterNonUniqueBy = (arr, fn) => const filterNonUniqueBy = (arr, fn) =>
arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j))); arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));
@ -710,6 +711,7 @@ const merge = (...objs) =>
}, {}), }, {}),
{} {}
); );
const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2];
const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates)); const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
@ -960,9 +962,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args));
const remove = (arr, func) => const remove = (arr, func) =>
Array.isArray(arr) Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => { ? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1); arr.splice(arr.indexOf(val), 1);
return acc.concat(val); return acc.concat(val);
}, []) }, [])
: []; : [];
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
const renameKeys = (keysMap, obj) => const renameKeys = (keysMap, obj) =>
@ -1321,4 +1323,4 @@ const zipWith = (...array) => {
); );
}; };
export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith }; export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith };

10
dist/_30s.js vendored
View File

@ -333,6 +333,7 @@
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), (acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
[] []
); );
const filterFalsy = arr => arr.filter(Boolean);
const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i)); const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));
const filterNonUniqueBy = (arr, fn) => const filterNonUniqueBy = (arr, fn) =>
arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j))); arr.filter((v, i) => arr.every((x, j) => (i === j) === fn(v, x, i, j)));
@ -716,6 +717,7 @@
}, {}), }, {}),
{} {}
); );
const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2];
const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn]));
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates)); const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n);
@ -966,9 +968,9 @@
const remove = (arr, func) => const remove = (arr, func) =>
Array.isArray(arr) Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => { ? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1); arr.splice(arr.indexOf(val), 1);
return acc.concat(val); return acc.concat(val);
}, []) }, [])
: []; : [];
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
const renameKeys = (keysMap, obj) => const renameKeys = (keysMap, obj) =>
@ -1410,6 +1412,7 @@
exports.extendHex = extendHex; exports.extendHex = extendHex;
exports.factorial = factorial; exports.factorial = factorial;
exports.fibonacci = fibonacci; exports.fibonacci = fibonacci;
exports.filterFalsy = filterFalsy;
exports.filterNonUnique = filterNonUnique; exports.filterNonUnique = filterNonUnique;
exports.filterNonUniqueBy = filterNonUniqueBy; exports.filterNonUniqueBy = filterNonUniqueBy;
exports.findKey = findKey; exports.findKey = findKey;
@ -1520,6 +1523,7 @@
exports.median = median; exports.median = median;
exports.memoize = memoize; exports.memoize = memoize;
exports.merge = merge; exports.merge = merge;
exports.midpoint = midpoint;
exports.minBy = minBy; exports.minBy = minBy;
exports.minDate = minDate; exports.minDate = minDate;
exports.minN = minN; exports.minN = minN;

View File

@ -1136,6 +1136,20 @@
"hash": "a6d182258648783ab09e72d4c40ac9de0dd3687a3b82c27715efab34d1836e1c" "hash": "a6d182258648783ab09e72d4c40ac9de0dd3687a3b82c27715efab34d1836e1c"
} }
}, },
{
"id": "filterFalsy",
"type": "snippetListing",
"attributes": {
"tags": [
"array",
"beginner"
],
"archived": false
},
"meta": {
"hash": "313401bff0dc161b9bfb2b123f7a98eb6630dc5d2ae1bb31400a340203a50255"
}
},
{ {
"id": "filterNonUnique", "id": "filterNonUnique",
"type": "snippetListing", "type": "snippetListing",
@ -2803,6 +2817,21 @@
"hash": "13f1b8dca2fb1c6ebba61abb7e5784fc80288e59f4979e463c5f4b81497d76bd" "hash": "13f1b8dca2fb1c6ebba61abb7e5784fc80288e59f4979e463c5f4b81497d76bd"
} }
}, },
{
"id": "midpoint",
"type": "snippetListing",
"attributes": {
"tags": [
"math",
"array",
"beginner"
],
"archived": false
},
"meta": {
"hash": "799134f9e026da20af240ed4d97b418bfac198394cd559cca19b143d3f7d4fb7"
}
},
{ {
"id": "minBy", "id": "minBy",
"type": "snippetListing", "type": "snippetListing",
@ -3304,7 +3333,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "dcdf66e8d0eb4a1761c6b767b8cc350757087ae817ec371436faab0fff7c0051" "hash": "4815876fd6dbb17ad34c0d8918e7a72d837104f9beee7dc51b0fa73057b9e83e"
} }
}, },
{ {
@ -3676,7 +3705,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "2fd54c9fc1fb5b0a981df69501b518d5830ea77544d4d5290c7cc13745ca00ea" "hash": "ec9cb9384817f84cf0bacd62a23b69b2304fa2cf0352b16d3950b21d48c04f11"
} }
}, },
{ {

View File

@ -1675,6 +1675,27 @@
"hash": "a6d182258648783ab09e72d4c40ac9de0dd3687a3b82c27715efab34d1836e1c" "hash": "a6d182258648783ab09e72d4c40ac9de0dd3687a3b82c27715efab34d1836e1c"
} }
}, },
{
"id": "filterFalsy",
"type": "snippet",
"attributes": {
"fileName": "filterFalsy.md",
"text": "Filters out the falsy values in an array.\r\n\r\nUse `Array.prototype.filter()` to get an array containing only truthy values.",
"codeBlocks": {
"es6": "const filterFalsy = arr => arr.filter(Boolean);",
"es5": "var filterFalsy = function filterFalsy(arr) {\n return arr.filter(Boolean);\n};",
"example": "filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1]"
},
"tags": [
"array",
"beginner"
]
},
"meta": {
"archived": false,
"hash": "313401bff0dc161b9bfb2b123f7a98eb6630dc5d2ae1bb31400a340203a50255"
}
},
{ {
"id": "filterNonUnique", "id": "filterNonUnique",
"type": "snippet", "type": "snippet",
@ -4126,6 +4147,28 @@
"hash": "13f1b8dca2fb1c6ebba61abb7e5784fc80288e59f4979e463c5f4b81497d76bd" "hash": "13f1b8dca2fb1c6ebba61abb7e5784fc80288e59f4979e463c5f4b81497d76bd"
} }
}, },
{
"id": "midpoint",
"type": "snippet",
"attributes": {
"fileName": "midpoint.md",
"text": "Calculates the midpoint between two pairs of (x,y) points.\n\nDestructure the array to get `x1`, `y1`, `x2` and `y2`, calculate the midpoint for each dimension by dividing the sum of the two endpoints by `2`.",
"codeBlocks": {
"es6": "const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2];",
"es5": "function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); }\n\nfunction _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nvar midpoint = function midpoint(_ref, _ref2) {\n var _ref3 = _slicedToArray(_ref, 2),\n x1 = _ref3[0],\n y1 = _ref3[1];\n\n var _ref4 = _slicedToArray(_ref2, 2),\n x2 = _ref4[0],\n y2 = _ref4[1];\n\n return [(x1 + x2) / 2, (y1 + y2) / 2];\n};",
"example": "midpoint([2, 2], [4, 4]); // [3, 3]\nmidpoint([4, 4], [6, 6]); // [5, 5]\nmidpoint([1, 3], [2, 4]); // [1.5, 3.5]"
},
"tags": [
"math",
"array",
"beginner"
]
},
"meta": {
"archived": false,
"hash": "799134f9e026da20af240ed4d97b418bfac198394cd559cca19b143d3f7d4fb7"
}
},
{ {
"id": "minBy", "id": "minBy",
"type": "snippet", "type": "snippet",
@ -4854,7 +4897,7 @@
"codeBlocks": { "codeBlocks": {
"es6": "const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));", "es6": "const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));",
"es5": "var pipeAsyncFunctions = function pipeAsyncFunctions() {\n for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {\n fns[_key] = arguments[_key];\n }\n\n return function (arg) {\n return fns.reduce(function (p, f) {\n return p.then(f);\n }, Promise.resolve(arg));\n };\n};", "es5": "var pipeAsyncFunctions = function pipeAsyncFunctions() {\n for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {\n fns[_key] = arguments[_key];\n }\n\n return function (arg) {\n return fns.reduce(function (p, f) {\n return p.then(f);\n }, Promise.resolve(arg));\n };\n};",
"example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async () => {\n console.log(await sum(5)); // 15 (after one second)\n})();" "example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async() => {\n console.log(await sum(5)); // 15 (after one second)\n})();"
}, },
"tags": [ "tags": [
"adapter", "adapter",
@ -4865,7 +4908,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "dcdf66e8d0eb4a1761c6b767b8cc350757087ae817ec371436faab0fff7c0051" "hash": "4815876fd6dbb17ad34c0d8918e7a72d837104f9beee7dc51b0fa73057b9e83e"
} }
}, },
{ {
@ -5401,7 +5444,7 @@
"fileName": "remove.md", "fileName": "remove.md",
"text": "Removes elements from an array for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`).", "text": "Removes elements from an array for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`).",
"codeBlocks": { "codeBlocks": {
"es6": "const remove = (arr, func) =>\n Array.isArray(arr)\n ? arr.filter(func).reduce((acc, val) => {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, [])\n : [];", "es6": "const remove = (arr, func) =>\n Array.isArray(arr)\n ? arr.filter(func).reduce((acc, val) => {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, [])\n : [];",
"es5": "var remove = function remove(arr, func) {\n return Array.isArray(arr) ? arr.filter(func).reduce(function (acc, val) {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, []) : [];\n};", "es5": "var remove = function remove(arr, func) {\n return Array.isArray(arr) ? arr.filter(func).reduce(function (acc, val) {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, []) : [];\n};",
"example": "remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]" "example": "remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]"
}, },
@ -5412,7 +5455,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "2fd54c9fc1fb5b0a981df69501b518d5830ea77544d4d5290c7cc13745ca00ea" "hash": "ec9cb9384817f84cf0bacd62a23b69b2304fa2cf0352b16d3950b21d48c04f11"
} }
}, },
{ {

View File

@ -757,6 +757,13 @@
], ],
"description": "Generates an array, containing the Fibonacci sequence, up until the nth term.\n\nCreate an empty array of the specific length, initializing the first two values (`0` and `1`).\nUse `Array.prototype.reduce()` to add values into the array, using the sum of the last two values, except for the first two" "description": "Generates an array, containing the Fibonacci sequence, up until the nth term.\n\nCreate an empty array of the specific length, initializing the first two values (`0` and `1`).\nUse `Array.prototype.reduce()` to add values into the array, using the sum of the last two values, except for the first two"
}, },
"filterFalsy": {
"prefix": "30s_filterFalsy",
"body": [
"const filterFalsy = arr => arr.filter(Boolean);"
],
"description": "Filters out the falsy values in an array."
},
"filterNonUnique": { "filterNonUnique": {
"prefix": "30s_filterNonUnique", "prefix": "30s_filterNonUnique",
"body": [ "body": [
@ -1826,6 +1833,13 @@
], ],
"description": "Creates a new object from the combination of two or more objects.\n\nUse `Array.prototype.reduce()` combined with `Object.keys(obj)` to iterate over all objects and keys.\nUse `hasOwnProperty()` and `Array.prototype.concat()` to append values for keys existing in multiple objects" "description": "Creates a new object from the combination of two or more objects.\n\nUse `Array.prototype.reduce()` combined with `Object.keys(obj)` to iterate over all objects and keys.\nUse `hasOwnProperty()` and `Array.prototype.concat()` to append values for keys existing in multiple objects"
}, },
"midpoint": {
"prefix": "30s_midpoint",
"body": [
"const midpoint = ([x1, y1], [x2, y2]) => [(x1 + x2) / 2, (y1 + y2) / 2];"
],
"description": "Calculates the midpoint between two pairs of (x,y) points.\n\nDestructure the array to get `x1`, `y1`, `x2` and `y2`, calculate the midpoint for each dimension by dividing the sum of the two endpoints by `2`"
},
"minBy": { "minBy": {
"prefix": "30s_minBy", "prefix": "30s_minBy",
"body": [ "body": [
@ -2428,9 +2442,9 @@
"const remove = (arr, func) =>", "const remove = (arr, func) =>",
" Array.isArray(arr)", " Array.isArray(arr)",
" ? arr.filter(func).reduce((acc, val) => {", " ? arr.filter(func).reduce((acc, val) => {",
" arr.splice(arr.indexOf(val), 1);", " arr.splice(arr.indexOf(val), 1);",
" return acc.concat(val);", " return acc.concat(val);",
" }, [])", " }, [])",
" : [];" " : [];"
], ],
"description": "Removes elements from an array for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`)" "description": "Removes elements from an array for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`)"