1.0.2 • Published 10 years ago
pure-swap v1.0.2
pure-swap
A pure function to swap the position of two elements in the array
Installation
$ npm install pure-swap --saveUsage
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
indexToSwapAn index of array element to swap - Number
indexToBeSwappedAn index of array element to be swapped
Return
- Array: Result
License
MIT © Philipp Alferov