Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const noop = arg => arg;
const combine = () => Array.from(arguments).reduce((a, b) => a.concat(b));
const compact = arr => arr.filter(el => el);
const difference = () => {
var others = Array.from(arguments).slice(1).reduce((a, b) => a.concat(b));
return arguments[0].filter(el => !others.some(exclude => el === exclude));
};
const head = arr => arr[0];
const initial = arr => arr.slice(0, arr.length-1);
const intersection = () => {
var len = arguments.length
return [...Set(
Array.from(arguments)
.map(arr => [...Set(arr)])
.reduce((a, b) => a.concat(b))
.filter((toFind, i, arr) => arr.filter(el => el === toFind).length == len)
)];
};
const last = arr => arr[arr.length-1];
const max = arr => Math.max(...arr);
const min = arr => Math.min(...arr);
const product = arr => arr.reduce((a, b) => a * b);
const sortedIndex = (arr, value) => [value].concat(arr).sort().indexOf(value);
const sum = arr => arr.reduce((a, b) => a + b);
const tail = arr => arr.slice(1);
const union = () => [...Set(
Array.from(arguments).reduce((a, b) => a.concat(b))
)];
const unique = arr => [...Set(arr)];
const without = () => {
var values = Array.from(arguments).slice(1);
return arguments[0].filter(el => !values.some(exclude => el === exclude));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.