compact
function just returns a newArray
without falsy values.
A filter
could do the trick using a simple isTruthy
expression.
[ ...list ].filter(value => value)
const compact = (list) => [ ...list ].filter((value) => value);
new Function('o', 'p', `try{return o.${path}}catch(_){return p}`)(object, placeholder)
const get = (object, path, placeholder = null) => {
try {
const value = new Function('object', `return object.${path}`)(object);
return value !== undefined ? value : placeholder;
} catch (err) {
return placeholder;
}
};
[ ...new Set(list) ]
const unique = (list) => [ ...new Set(list) ];
your _.get is terrible, just have
const get = (o, path) = path.split('.').reduce((acc, k) => acc[k], o)