Skip to content

Allow compareMultiple/orderBy to accept compare functions #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2018

Conversation

techrah
Copy link

@techrah techrah commented Apr 22, 2018

See #3763 for rationale.

    QUnit.test('should work with `orders` specified as compare functions', function(assert) {
      assert.expect(3);

      function compareStrings(a, b) { return a < b ? -1 : a > b ? 1 : 0 }
      function compareStringsDesc(a, b) { return -compareStrings(a, b) }
      function compareNumbers(a, b) { return a - b }

      var actual = _.orderBy(objects, 'a', compareStringsDesc);
      assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);

      actual = _.orderBy(objects, ['a'], [compareStringsDesc]);
      assert.deepEqual(actual, [objects[1], objects[3], objects[0], objects[2]]);

      actual = _.orderBy(objects, ['a', 'b'], [compareStringsDesc, compareNumbers]);
      assert.deepEqual(actual, [objects[3], objects[1], objects[2], objects[0]]);
    });

@jsf-clabot
Copy link

jsf-clabot commented Apr 22, 2018

CLA assistant check
All committers have signed the CLA.

@@ -11,7 +11,7 @@ import compareAscending from './compareAscending.js'
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {boolean[]|string[]} orders The order to sort by for each property.
* @param {(string|function)[]} orders The order to sort by for each property.
Copy link
Author

@techrah techrah Apr 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention here is to say that

  • an array of a combination of strings and functions is possible,

as opposed to

  • either an array of strings or and array of functions is allowed

@jdalton
Copy link
Member

jdalton commented May 1, 2018

Thanks @ryanhomer!

@kikonen
Copy link

kikonen commented Sep 6, 2018

Q: When one could expect release containing this comparator addition to be available?

@jdalton
Copy link
Member

jdalton commented Sep 6, 2018

Hi @kikonen!

This did not land in v4 so will have a possibility of showing up in v5
(a future major release, whenever that is).

@lock
Copy link

lock bot commented Sep 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

4 participants