Merge remote-tracking branch 'origin/master'

This commit is contained in:
Angelos Chalaris
2019-12-31 13:17:19 +02:00
11 changed files with 100 additions and 101 deletions

View File

@ -240,9 +240,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
@ -1380,15 +1380,10 @@ const weightedSample = (arr, weights) => {
let roll = Math.random();
return arr[
weights
.reduce((acc, w, i) =>
i === 0 ? [w] : [...acc, acc[acc.length - 1] + w],
[]
)
.findIndex((v, i, s) =>
roll >= (i === 0 ? 0 : s[i - 1]) && roll < v
)
.reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])
.findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)
];
}
};
const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x);
const without = (arr, ...args) => arr.filter(v => !args.includes(v));
const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean);