sub-array-order
v0.1.3
Published
A mini library to get sub array in the order that they are arranged in parent array or the reverse of it
Downloads
4
Readme
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];
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 ]