const activeSorts = {
aFirst: 0,
zFirst: 0,
cheapFirst: 1,
expensiveFirst: 0,
};
const cards = somedata
.sort(
(activeSorts.cheapFirst && sortCheapFirst) ||
(activeSorts.aFirst && sortAlphabet) ||
(activeSorts.expensiveFirst && sortExpensiveFirst)
);
I’m trying to sort data based on conditions in activeSorts
. if a sort type value is 1
, data should be sorted based on that, and if it’s 0
, it shouldn’t.
The problem is that it requires me to have at least one sort enabled. If I make all of them 0
, I get this:
TypeError: The comparison function must be either a function or undefined
What should I do?