Skip to content

Instantly share code, notes, and snippets.

// quick idea to reduce an array by automatically merging result of iteratee(current, i, src) onto acc
const reduceMerge = (arr, iteratee) =>
arr.reduce((acc, cur, i, src) => {
const val = iteratee(cur, i, src)
// allow falsy returns to result in noop for this iteration
if (!val) {
return acc
} else if (val.constructor === Object) {
return Object.assign(acc, val)
}
@rolandcoops
rolandcoops / webpack.config.js
Last active May 6, 2019 10:50
Idea for explicitly splitting out chunks for specific groups of vendor modules
const { configureCacheGroups } = require('./webpack.utils')
const cacheGroups = configureCacheGroups({
'react': ['react', 'react-dom'],
'lodash': ['lodash'],
'redux': ['redux', 'react-redux'],
'semantic-ui': ['semantic-ui-react'],
'core-js': ['core-js'],
})
@rolandcoops
rolandcoops / roundUpBaseInRange.js
Last active November 16, 2017 18:37
Calculate ‘nice’ graph domain by rounding up number through a base-10 range. (ES6)
// Round up to nearest base, in base 10. Works for both negative/positive numbers and numbers -1 < n < 1.
// Useful for calculating a sensible/readible graph domain max if you input the max value of your data.
export const roundUpBaseInRange = (n, bases = [1, 2, 4, 5, 6, 8, 10]) => {
// Store the sign, so we can restore it for the result lateron
const sign = Math.sign(n)
// Get modulus (remove sign) for next steps in calculation
const modulus = Math.abs(n)
// Calculate base10 exponent (i.e. amount of digits as float instead of integer)