Custom util to get weekday name or number

const getDayNameOrNo = (value) => {
  const mappings = [
    [0, "sunday"],
    [1, "monday"],
    [2, "tuesday"],
    [3, "wednesday"],
    [4, "thursday"],
    [5, "friday"],
    [6, "saturday"],
  ];

  const match = mappings.find(
    ([dayNo, name]) => dayNo === value || name === value
  );

  if (!match) return;

  const [matchedNo, matchedName] = match;
  return matchedNo === value ? matchedName : matchedNo;
};

console.log(getDayNameOrNo(0)); // sunday
console.log(getDayNameOrNo("sunday")); // 0
console.log(getDayNameOrNo("friday")); // 5