move-element

0.1.0 • Public • Published

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

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i move-element

    Weekly Downloads

    0

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • ttmarek