This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandomValue(min, max) { | |
return Math.floor(Math.random() * (max - min)) + min; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const map = new Map([ | |
[cond1 && cond2, 'case1'], | |
[cond2, 'case2'], | |
[cond3, 'case3'] | |
]) | |
return map.get(true) || 'defaultCase'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolve: { | |
alias: Object.keys(tsconfig.compilerOptions.paths).reduce((aliases, aliasName) => { | |
aliases[aliasName] = path.resolve(__dirname, `src/${tsconfig.compilerOptions.paths[aliasName][0]}`) | |
return aliases | |
}, {}) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const sanitizeListRestProps = props => | |
Object.keys(props) | |
.filter(propName => !injectedProps.includes(propName)) | |
.reduce((acc, key) => ({ ...acc, [key]: props[key] }), {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var groupBy = function(array, key) { | |
return array.reduce(function(acc, cur) { | |
(acc[cur[key]] = acc[cur[key]] || []).push(cur); | |
return acc; | |
}, {}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepClone(object){ | |
var newObject = {}; | |
for(var key in object){ | |
if(typeof object[key] === 'object' && object[key] !== null ){ | |
newObject[key] = deepClone(object[key]); | |
}else{ | |
newObject[key] = object[key]; | |
} | |
} | |
return newObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myNew(constructor, ...args) { | |
const obj = {} | |
Object.setPrototypeOf(obj, constructor.prototype); | |
return constructor.apply(obj, args) || obj | |
} | |
function Cat(color, name) { | |
this.color = color | |
this.name = name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [1, [1, 2, [3, 4]], [2, 4]] -> [1, 1, 2, 3, 4, 2, 4] | |
const flatten = (arr) => arr.reduce((flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten), []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"presets": [ | |
"@babel/preset-react", | |
["@babel/preset-env", { | |
"targets": "> 0.25%, not dead", | |
}] | |
], | |
"plugins": [ | |
"add-module-exports", | |
"transform-react-jsx", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const significantDigits = (value = 0) => | |
new Intl.NumberFormat(formats.LOCALES, { minimumSignificantDigits: 3, maximumSignificantDigits: 4 }).format(value); |
NewerOlder