sub-array-order

0.1.3 • Public • Published

array-order

This is a mini library, it was pretty handy to me , imagine this there is a certain sub array you have and then you want the sub array to have the same order as the parent does,
Example,

var parent = [1,2,3,4,5,6,7,8,9];
var sub = [8,2,1,6,4];

To achieve this you simply call
  var newArr = getOrderedArray(parent, sub);

Which will give you [1,2,4,6,8]

And to get the reverse of this simply add one more parameter to it, and set it to true


Installation

  yarn add sub-array-order

Usage

  const getOrderedArray = require('sub-array-order');
  getOrderedArray([1,2,3,4,5,6,7,8,9,10], [8,3,4,1]);

Result

  [ 1, 3, 4, 8 ]

Reverse

  getOrderedArray([1,2,3,4,5,6,7,8,9,10], [8,3,4,1], true);

Result

  [ 8, 4, 3, 1 ]

Readme

Keywords

none

Package Sidebar

Install

npm i sub-array-order

Weekly Downloads

3

Version

0.1.3

License

MIT

Unpacked Size

2.58 kB

Total Files

4

Last publish

Collaborators

  • y2z