Miss any of our Open RFC calls?Watch the recordings here! »

sort-by-chapter

1.0.15 • Public • Published

sort-by-chapter

Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee.

Inline docs Build Status Coverage Status

Examples

Basic

import sortByChapter from 'sort-by-chapter';
 
const arr = [
  'Goal 1',
  'Goal 2',
  'Goal 3',
  'Strategy 1.1',
  'Strategy 1.2',
  'Strategy 1.3',
  'Activity 1.1.1',
  'Activity 1.1.2',
  'Activity 1.1.3'
];
const newArr = sortByChapter(arr);
console.log(newArr);
[ 'Goal 1',
  'Strategy 1.1',
  'Activity 1.1.1',
  'Activity 1.1.2',
  'Activity 1.1.3',
  'Strategy 1.2',
  'Strategy 1.3',
  'Goal 2',
  'Goal 3' ]

Specify Attribute

import sortByChapter from 'sort-by-chapter';
 
const arr = [
  { title: 'Goal 1',
  { title: 'Goal 2' },
  { title: 'Goal 3' },
  { title: 'Strategy 1.1' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' }
];
const newArr = sortByChapter(arr, { attribute: 'title' });
console.log(newArr);

or

import sortByChapter from 'sort-by-chapter';
 
const arr = [
  { title: 'Goal 1',
  { title: 'Goal 2' },
  { title: 'Goal 3' },
  { title: 'Strategy 1.1' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' }
];
const newArr = sortByChapter(arr, 'title');
console.log(newArr);
[ { title: 'Goal 1' },
  { title: 'Strategy 1.1' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Goal 2' },
  { title: 'Goal 3' } ]

Install

npm i sort-by-chapter

DownloadsWeekly Downloads

4

Version

1.0.15

License

MIT

Unpacked Size

16 kB

Total Files

10

Last publish

Collaborators

  • avatar