Skip to content

Instantly share code, notes, and snippets.

View mi-mina's full-sized avatar

Esperanza Moreno Cruz mi-mina

View GitHub Profile
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)];
// Returns all non-falsy values from an array
[...].filter(Boolean);
// Just plain english
[...].every(Number.isFinite);
// Array destructuring to see matching elements
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
function getOptionalProperty(obj, ...props) {
const val = obj[props[0]];
if (props.length === 1 || !val) return val;
const rest = props.slice(1);
return getOptionalProperty.apply(null, [val, ...rest]);
}
const user = { name: "fluffy" };
const zip = getOptionalProperty(user, "address", "zip");
console.log("zip", zip);
@mi-mina
mi-mina / esperanza-moreno-personal-portfolio.markdown
Last active October 20, 2016 12:28
Esperanza Moreno. Personal Portfolio