diff --git a/README.md b/README.md index 1a64e5793..92bda6ba1 100644 --- a/README.md +++ b/README.md @@ -4507,11 +4507,11 @@ isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true Results in a boolean representation of a specific date. Pass the specific date object firstly. -Use `Date.getDay()` to check weekday then return a boolean. +Use `Date.getDay()` to check weekday by using a modulo operator and then returning a boolean. ```js const isWeekday = (t = new Date()) => { - return t.getDay() >= 1 && t.getDay() <= 5; + return t.getDay() % 6 !== 0; }; ``` @@ -4816,6 +4816,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/date.html b/docs/date.html index 5ee8bd6c2..196cd9d9b 100644 --- a/docs/date.html +++ b/docs/date.html @@ -135,8 +135,8 @@
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
Check if a date is the same as another date.
Use Date.prototype.toISOString() and strict equality checking (===) to check if the first date is the same as the second one.
const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString();
isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true -
Take your JavaScript to the next level. Gain an understanding of callbacks, higher order functions, closure, asynchronous and object-oriented JavaScript!
Results in a boolean representation of a specific date.
Pass the specific date object firstly. Use Date.getDay() to check weekday then return a boolean.
const isWeekday = (t = new Date()) => { - return t.getDay() >= 1 && t.getDay() <= 5; +
Take your JavaScript to the next level. Gain an understanding of callbacks, higher order functions, closure, asynchronous and object-oriented JavaScript!
Results in a boolean representation of a specific date.
Pass the specific date object firstly. Use Date.getDay() to check weekday by using a modulo operator and then returning a boolean.
const isWeekday = (t = new Date()) => { + return t.getDay() % 6 !== 0; };
isWeekday(); // true (if current date is 2019-07-19)
Results in a boolean representation of a specific date.
Pass the specific date object firstly. Use Date.getDay() to check weekend then return a boolean.
const isWeekend = (t = new Date()) => { diff --git a/docs/function.html b/docs/function.html index fb90629bd..41700dc2a 100644 --- a/docs/function.html +++ b/docs/function.html @@ -157,6 +157,7 @@ console.log< + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/snippets/checkProp.md b/snippets/checkProp.md index 627fa7cb8..465b862f1 100644 --- a/snippets/checkProp.md +++ b/snippets/checkProp.md @@ -22,6 +22,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/test/_30s.js b/test/_30s.js index c5fb8b943..7110da6b0 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -659,7 +659,7 @@ const isValidJSON = str => { } }; const isWeekday = (t = new Date()) => { - return t.getDay() >= 1 && t.getDay() <= 5; + return t.getDay() % 6 !== 0; }; const isWeekend = (t = new Date()) => { return t.getDay() === 0 || t.getDay() === 6;