Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Algorithm to select new element from array everyday (Wordle)

Like Wordle, I’m trying to implement an algorithm to select a new element from an array everyday.

My current algorithm is as:

function getRandomElement(): string {
  const epochMS = new Date(2022, 0).valueOf();
  const now = Date.now();
  const msInDay = 86400000;
  const daysSinceEpochIndex = Math.floor((now - epochMS) / msInDay);

  return array[daysSinceEpochIndex % array.length];
}

The issue I’m facing is that while it work, epochMS has a different time zone than now due to daylight savings. This means it selects a new element from the array an hour after it should. How do I account for time zone differences and make it select a new element every 24 hours (i.e., at midnight) no matter where in the world the user is? Thank you.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!