Created
November 28, 2017 04:25
-
-
Save ivomarsan/4764462f82c49857d5b5be1367ba2982 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findByFieldRange = field => (list, range) => | |
list.filter(obj => obj[field] >= range[0] && obj[field] <= range[1]); | |
const getAllByField = field => list => list.filter(obj => obj[field]); | |
const findIn = list => ({ | |
by: field => ({ | |
between: (start, end = start) => | |
findByFieldRange(field)(list, [start, end]), | |
getAll: () => getAllByField(field)(list), | |
}), | |
}); | |
const list = [ | |
{ id: 1, name: 'Suissa' }, | |
{ id: 2, name: 'Jean' }, | |
{ id: 3, name: 'Carlo' }, | |
{ id: 4, name: 'Nascimento' }, | |
{ name: 'Debochado :P' }, | |
]; | |
const between = findIn(list) | |
.by('id') | |
.between(1); | |
const getAll = findIn(list) | |
.by('id') | |
.getAll(); | |
console.log('between', between); | |
console.log('getAll', getAll); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment