0.1.0 • Published 8 years ago

move-element v0.1.0

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

move-element

js-standard-style npm version

Move an array element to a given position.

Install

    npm install --save --save-exact move-element

Usage

    const moveElement = require('move-element')
    // Say you have an array of fruits
    const fruits = ['Oranges', 'Apples', 'Bananas', 'Pineapples']
    // And you want to swap the positions of 'Apples' and 'Bananas'
    // First you make a function that returns true for the element you want to move
    const isApples = (x) => x === 'Apples'
    // Then you call moveElement with the index you want to move the element to
    const newArray = moveElement(fruits, isApple, 2)
    // Then newArray will be set to:
    // ['Oranges', 'Bananas', 'Apples', 'Pineapples']

License

MIT © Thomas Marek