Files
30-seconds-of-code/snippets/isWeekend.md
Robert Mennell 7506499f8c Simplify the comparison for a weekend
Since a weekend is either `0` or `6` from `Date#getDay()`, using `X % 6 === 0` will return the right Boolean value and lead to less function calls or comparisons
2019-07-19 15:43:50 -07:00

17 lines
392 B
Markdown

### isWeekend
Results in a boolean representation of a specific date.
Pass the specific date object firstly.
Use `Date.getDay()` to check weekend based on the day being returned as 0 - 6 using a modulo operation then return a boolean.
```js
const isWeekend = (t = new Date()) => {
return t.getDay() % 6 === 0;
};
```
```js
isWeekend(); // 2018-10-19 (if current date is 2018-10-18)
```