This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6 | |
export function getDayDate(date: Date | string, weekDay: WeekDays) { | |
const _date = new Date(date) | |
const day = _date.getDay() | |
if (day === weekDay) return _date | |
const diff = | |
(day === 0 || day - weekDay === 0 | |
? weekDay - 7 | |
: weekDay === 0 | |
? weekDay + 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Array} arr - Array to be filtered from | |
* @param {Array} props - array of keys that needs to be unique | |
* @returns {Array} - unique array | |
*/ | |
const unique = (arr, props = []) => [...new Map(arr.map(entry => [props.map(k => entry[k]).join('|'), entry])).values()] |