mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
re-formate wth standard.js
This commit is contained in:
@ -47,16 +47,16 @@ const DateToDay = (date) => {
|
|||||||
// extarct the date
|
// extarct the date
|
||||||
const [day, month, year] = date.split('/').map((x) => Number(x))
|
const [day, month, year] = date.split('/').map((x) => Number(x))
|
||||||
// check the data are valid or not.
|
// check the data are valid or not.
|
||||||
if ( day < 0 || day > 31 || month > 12 || month < 0) {
|
if (day < 0 || day > 31 || month > 12 || month < 0) {
|
||||||
return new TypeError('Date is not valid.')
|
return new TypeError('Date is not valid.')
|
||||||
}
|
}
|
||||||
// divide year to century and yearDigit value.
|
// divide year to century and yearDigit value.
|
||||||
const yearDigit = (year % 100)
|
const yearDigit = (year % 100)
|
||||||
const century = Math.floor(year / 100)
|
const century = Math.floor(year / 100)
|
||||||
// Apply the algorithm shown above
|
// Apply the algorithm shown above
|
||||||
const weekDay = Math.abs((day + Math.floor((2.6 * calcMonthList[month]) - 0.2) - (2 * century) + yearDigit + Math.floor(yearDigit/4) + Math.floor(century/4)) % 7)
|
const weekDay = Math.abs((day + Math.floor((2.6 * calcMonthList[month]) - 0.2) - (2 * century) + yearDigit + Math.floor(yearDigit / 4) + Math.floor(century / 4)) % 7)
|
||||||
// return the weekDay name.
|
// return the weekDay name.
|
||||||
return daysNameList[weekDay];
|
return daysNameList[weekDay]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example : DateToDay("18/12/2020") => Friday
|
// Example : DateToDay("18/12/2020") => Friday
|
||||||
|
Reference in New Issue
Block a user