Make a portal between two arrays and transfer items between them
$ npm install array-portal --save
// List of things you want to sell
const offer = ['car', 'house', 'banana'];
// Array of stuff you've already sold
const sold = ['table'];
// Now you've sold the banana and want to move it from the offer-array to the sold-array
ArrayPortal({
caller: 'banana'
input: offer,
output: sold
});
// The output you get is:
{
input: ['car', 'house'],
output: ['table', 'banana']
}
// Sometimes you've an array with a lot of objects - so you cannot identify an item by its name
const todos = [{ todo_id: 1, text: 'Take out the trash'}, { todo_id: 2, text: 'Wash the dishes' }];
const done = [];
// But thats no problem... let's say you've taken out the trash (so the todo_id: 1)
ArrayPortal({
caller: {
todo_id: 1
},
input: todos,
output: done
});
// The output you get is:
{
input: [{ todo_id: 2, text: 'Wash the dishes' }],
output: [{ todo_id: 1, text: 'Take out the trash' }]
}
110,029 op/s
// Run and Watch tests
$ npm run test -- -w
// Just run tests
$ npm run test
// Create new build
$ npm run build
// Run benchmark
$ npm run bench