Skip to content

Instantly share code, notes, and snippets.

View vasylpb's full-sized avatar

Vasyl vasylpb

  • Ukraine
View GitHub Profile
function getRandomValue(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
const map = new Map([
[cond1 && cond2, 'case1'],
[cond2, 'case2'],
[cond3, 'case3']
])
return map.get(true) || 'defaultCase';
resolve: {
alias: Object.keys(tsconfig.compilerOptions.paths).reduce((aliases, aliasName) => {
aliases[aliasName] = path.resolve(__dirname, `src/${tsconfig.compilerOptions.paths[aliasName][0]}`)
return aliases
}, {})
},
export const sanitizeListRestProps = props =>
Object.keys(props)
.filter(propName => !injectedProps.includes(propName))
.reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
@vasylpb
vasylpb / groupBy
Last active August 15, 2020 15:56
var groupBy = function(array, key) {
return array.reduce(function(acc, cur) {
(acc[cur[key]] = acc[cur[key]] || []).push(cur);
return acc;
}, {});
};
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;
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
}
// [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), []);
@vasylpb
vasylpb / gist:8077b41c2053ceee6e6c30f85db66087
Created April 24, 2019 14:20
babel configuration for react
{
"presets": [
"@babel/preset-react",
["@babel/preset-env", {
"targets": "> 0.25%, not dead",
}]
],
"plugins": [
"add-module-exports",
"transform-react-jsx",
const significantDigits = (value = 0) =>
new Intl.NumberFormat(formats.LOCALES, { minimumSignificantDigits: 3, maximumSignificantDigits: 4 }).format(value);