Set of DRY tools to work with array. Typescript style.
``
import { all } from "@vlr/array-tools"
const a = [1, 2, 3];
const allHigher = all(a, item => item > 2); // false
const allNumbers = all(a, isNumber); // true
`
`
const a = [
{ id: 1, name: 'a' },
{ id: 2, name: 'b' }
];
const b = [
{ id: 1, name: 'c' },
{ id: 2, name: 'd' }
];
const c = [
{ id: 2, name: 'b' },
{ id: 1, name: 'a' }
];
const anb = areEqual(a, b, item => item.id); // true
const anc = areEqual(a, c, item => item.id); // false
`
`
const a = [1, 2];
const b = [2, 3];
const result1 = intersect(a, b); // [2]
const result2 = except(a, b); // [1]
`
const a = [1, 2];
const b = flatMap(a, item => [item, 3]); // [1, 3, 2, 3];
`
const a = [1, 2, 3];
const result1 = first(a, item => item > 1); // 2
const result2 = last(a, item => item > 1); // 3
`
`
const a = [1, 2, 3];
const result1 = min(a, item => -item); // 3
const result2 = max(a, item => -item); // 1
`
``
const matches = regexToArray(/\d/g, 'a1b2c');
// two matches, matches[0][0] = '1', matches[1][0] = '2'
``
const a = [1, 2, 3, 4];
const result = splitInGroups(a, 2); // [[1, 2], [3, 4]];
`
const a = [
{ id: 1, name: 'a' },
{ id: 1, name: 'b' },
{ id: 2, name: 'c' },
{ id: 2, name: 'd' }
];
const result = unique(a, item => item.id); // [a[0], a[2]]
`
`
const items = [1, 2, 3, 4];
const result = trim(items, 2); // [1, 2]
``