Skip to content

michaelzoidl/array-portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Array Portal

Make a portal between two arrays and transfer items between them

Build Status devDependency Status Dependency Status

Install

$ npm install array-portal --save

Usage

// 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']
}

One step further

// 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' }]
}

Benchmark

110,029 op/s

Contribute

// 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

About

Make a portal between two arrays and transfer items between them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published