shaikzhafir / when-eat

Home Page:when-eat.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can refactor by abstracting methods to improve readability

adriangohjw opened this issue · comments

when-eat/routes/index.js

Lines 21 to 30 in e1d6fb3

if (!datesAreOnSameDay(dateNow, dateStored)) {
let scrape = await scrapeTime()
updateJSONTime(dateNow,scrape.subuhTime,scrape.maghribTime)
maghribTime = scrape.maghribTime
subuhTime = scrape.subuhTime
} else {
maghribTime = data.maghribTime
subuhTime = data.subuhTime
}

if (!datesAreOnSameDay(dateNow, dateStored)) {
  let scrape = await scrapeTime();
  updateJSONTime(dateNow, scrape.subuhTime, scrape.maghribTime);
}
[maghribTime, subuhTime] = getStoredTimings();
//...

// abstracted function for readability
function getStoredTimings() {
  return [data.maghribTime, data.subuhTime]
}