Socket
Book a DemoInstallSign in
Socket

pure-swap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pure-swap

Pure function to swap the position of two elements in the array

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

pure-swap

Build Status Dependency Status

A pure function to swap the position of two elements in the array

Installation

$ npm install pure-swap --save

Usage


var pureSwap = require('pure-swap');
var array = [1,2,3,4];
pureSwap(array, 1, 3); // => [1,4,3,2]
pureSwap(array, 3, 1); // => [1,4,3,2]

// It doesn't modify the original array
console.log(array) // => [1,2,3,4]

API

pureSwap(data, indexToSwap, indexToBeSwapped)

A pure function to swap the position of two elements in the array

Parameters

  • Array array: An array of data
  • Number indexToSwap An index of array element to swap
  • Number indexToBeSwapped An index of array element to be swapped

Return

  • Array: Result

License

MIT © Philipp Alferov

Keywords

array

FAQs

Package last updated on 01 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts