0.1.1 • Published 7 years ago

array-transfer v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

array-transfer npm version Build Status

Immutably transfer value from an array to another array

Installation

npm i array-transfer --save

Usage

const transfer = require('array-transfer');
const {source, destination} = transfer(['rupee', 'doggie'], ['macky'], 1, 0);
console.log(source, destination) // ['rupee'], ['doggie', 'macky']

Without ES6 destructuring

If you're within a project that doesn't use a transpiler like Babel, and would like to support legacy browsers, no worries!

const set = transfer(['rupee', 'doggie'], ['macky'], 1, 0);
console.log(set.source, set.destination) // ['rupee'], ['doggie', 'macky']

transfer(src, dest, start, end)

  • src - The array where the value will be taken from
  • dest - The array where the value will be transferred to
  • start - Which index in src the value will be taken from
  • end - Which index in end the value will be taken to

Use case

This is a typical use case for Trello-like apps where you want to move a task from its original list to another list. You may also find this useful if you're dealing with tree nodes where you want to transfer a node to another parent.

Running tests

npm test