reviewers-edition-compare

1.0.5 • Public • Published

This npm package exports a single argument comparison function. The function takes two Reviewers Edition strings as inputs and returns:

  • -1 if the first argument is an earlier Reviewers Edition than the second argument

  • 0 if the first argument is equal to the second argument

  • 1 if the first argument is a later Reviewers Edition than the second argument

This makes the function a suitable argument to Array.prototype.sort.

The following demonstration is also the test suite for the parser, using Node.js' built-in assert module.

Here is a list of Reviewers Edition strings in ascending order.

var sorted = [
  '1e1d', '1e2d', '1e', '1e2u1d', '1e2u', '1e2u1c1d', '1e2u1c2d',
  '3e', '3e1c', '3e2c', '3e3c', '3e2u', '3e11u',
  '4e1d', '4e2d', '4e', '4e99c1d', '4e100c',
  '5e1c', '5e2c', '5e1u', '5e2u', '5e3u1d',
  '1000e'
]

This test ensures that if we shuffle that list and resort it using the comparison function, it ends up in sorted order again.

require('assert').deepStrictEqual(
  require('array-shuffle')(sorted)
  .sort(require('reviewers-edition-compare')),
  sorted
)

This package is bundled with other functions for creating and manipulating Reviewers Editions in reved.

Package Sidebar

Install

npm i reviewers-edition-compare

Weekly Downloads

647

Version

1.0.5

License

MIT

Last publish

Collaborators

  • kemitchell