Owen Rossi-KeenO
Reactiflux4y ago
21 replies
Owen Rossi-Keen

✅ – ekomS – 23-35 Dec 21

Howdy all. I've got this sort function which prioritizes truthy values in an array:
    truthyFirst: (array, callback = emptyCallback) => {
      return array.sort((a, b) => {
        if (callback(a) && callback(b)) return 0;
        if (callback(b)) return 1;
        if (callback(a)) return -1;
      });
    },

Is there a better way to coerce the condition to its relevant value?
e.g. a && b -> 0, a -> -1, b -> 1
Was this page helpful?