0.1.1 • Published 8 years ago

order-align v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

orderAlign

Build Status XO code style npm version

In the order specified the array

Install

npm i order-align

Usage

const orderAlign = require('order-align');
orderAlign(orderList, dataArr, targetKey);

Example

String

const orderList = ['foo', 'bar', 'baz'];
const dataArr = ['baz', 'foo', 'bar'];

const result = orderAlign(orderList, dataArr);
console.log(result);
// [ 'foo', 'bar', 'baz' ]

Object

const orderList = ['foo', 'bar', 'baz'];
const dataArr = [
  {name: 'baz'},
  {name: 'foo'},
  {name: 'bar'}
];

const result = orderAlign(orderList, dataArr, 'name');
console.log(result);
// [ { name: 'foo' }, { name: 'bar' }, { name: 'baz' } ]