Created
September 21, 2021 04:06
-
-
Save brendomaciel/74fcb54d0b3a637a81abc69b5a2e1aa2 to your computer and use it in GitHub Desktop.
This file contains 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 helpMeTo = { | |
get: { | |
entry: { | |
from: (array) => { | |
return { | |
where: (property) => { | |
return { | |
equalsTo: (value) => { | |
return array.find((item) => item[property] === value); | |
}, | |
}; | |
}, | |
}; | |
}, | |
}, | |
}, | |
add: { | |
entry: (entry) => { | |
return { | |
into: (array) => { | |
array.push(entry); | |
return array; | |
}, | |
}; | |
}, | |
}, | |
}; | |
const users = [ | |
{ id: 1, name: 'Ana'}, | |
{ id: 2, name: 'Eva'}, | |
{ id: 3, name: 'John'}, | |
]; | |
console.log(helpMeTo.add.entry({ id: 4, name: 'Luka' }).into(users)); | |
console.log(helpMeTo.get.entry.from(users).where('name').equalsTo('John')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment