pure-swap
A pure function to swap the position of two elements in the array
Installation
$ npm install pure-swap --save
Usage
var pureSwap = ;var array = 1234;; // => [1,4,3,2]; // => [1,4,3,2] // It doesn't modify the original arrayconsole // => [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