Selecting a prize category based on two parameters I get an object with categories, first category has 2 types. Both types are in the first and second position but sorting is not constant.

I have to return category 1 with playLevel === 2 when bonusPlus is true and category 1 with playLevel === 1 otherwise.

Here is the code:

const getFirstCategory = (bonusPlus, prizeCategories) =&gt; {
  if (bonusPlus) {
    if (prizeCategories[0].playLevel === 2) {
      return [prizeCategories[0]];
    }
    return [prizeCategories[1]];
  }
  if (prizeCategories[0].playLevel === 1) {
    return [prizeCategories[0]];
  }
  return [prizeCategories[1]];
};


How can I reduce / beautify this code?
To make @kfx's answer more readable:

const getFirstCategory = (bonusPlus, prizeCategories) =&gt; {
  const bonusPlusLevel = bonusPlus ? 2 : 1;
  if (prizeCategories[0].playLevel === bonusPlusLevel) {
    return [prizeCategories[0]];
  }
  return [prizeCategories[1]];
};