Skip to content

Instantly share code, notes, and snippets.

@brendomaciel
Created September 21, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendomaciel/74fcb54d0b3a637a81abc69b5a2e1aa2 to your computer and use it in GitHub Desktop.
Save brendomaciel/74fcb54d0b3a637a81abc69b5a2e1aa2 to your computer and use it in GitHub Desktop.
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