# Builtin Ord / Compare method for primitives

**URL:** <https://es.discourse.group/t/builtin-ord-compare-method-for-primitives/724>\
**Category:** 💡 Ideas\
**Created:** [April 4, 2021, 2:08pm UTC](https://es.discourse.group/t/builtin-ord-compare-method-for-primitives/724 "2021-04-04T14:08:28Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [April 5, 2021, 2:12pm UTC](https://es.discourse.group/t/builtin-ord-compare-method-for-primitives/724/10 "2021-04-05T14:12:21Z")

</div>

I would personally be against the spaceship operator - it's an operator that's pretty much specific to the sort function. Python found a user-friendly way to do custom sorting without needing to introduce a sort operator - instead of having your custom sorter return -1/0/1, you instead tell python how to map an array value to a sortable key, that can be used to order the parameters. This is how it would look like in javascript:

```javascript
[{ thing: 'def' }, { thing: 'abc' }].sortBy(obj => obj.thing)

```

This will handle all but a few obscure use cases of the spaceship operator. Some popular libraries like lodash also provide helper methods such as this.

Also, if I were actually creating a data structure such as a priority queue (or any of the other data structures you mentioned), I would expect it to treat 0 and -0 as the same value (not ordering 0 above -0), and I would expect NaN to be just as invalid of a priority as a string (not giving it the highest priority).

---

_[View the full topic](https://es.discourse.group/t/builtin-ord-compare-method-for-primitives/724)._
