array-rearrange
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/array-rearrange package

2.2.2 • Public • Published

array-rearrange experimental Build Status

Reorder elements within array by index.

npm install array-rearrange

const reorder = require('array-rearrange')
 
let arr = reorder([9,8,7,6], [3,2,1,0]) // [6,7,8,9]
 
let arr2 = reorder([3,3, 2,2, 1,1], [2,1,0]) // [1,1, 2,2, 3,3]

API

array = reorder(array, index, stride=1)

Shuffle elements in array according to the index array passed. Permutes original array. index array should contain unique indexes. Pass stride to indicate groups of elements to shuffle.

Originally based on the reference solution, which turns out to be wrong, so algorithm is fully rewritten.

See also

Package Sidebar

Install

npm i array-rearrange

Weekly Downloads

148,669

Version

2.2.2

License

MIT

Unpacked Size

7.24 kB

Total Files

7

Last publish

Collaborators

  • dfcreative