2
0 Comments

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
Trending on Indie Hackers
Getting first 908 Paid Signups by Spending $353 ONLY. 24 comments I talked to 8 SaaS founders, these are the most common SaaS tools they use 20 comments What are your cold outreach conversion rates? Top 3 Metrics And Benchmarks To Track 19 comments How I Sourced 60% of Customers From Linkedin, Organically 12 comments Hero Section Copywriting Framework that Converts 3x 12 comments Join our AI video tool demo, get a cool video back! 12 comments