Last active
October 7, 2016 16:13
-
-
Save maxrolon/9363a0fcabc41b6ecd16c5adc030ddbd to your computer and use it in GitHub Desktop.
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
/* | |
* Compile an array of dates, between | |
* a start and end date. Provide the ability | |
* to skip days of the week. | |
*/ | |
const saveDay = { | |
monday:true, | |
tuesday:true, | |
wednesday:true, | |
thursday:false, | |
friday:false, | |
saturday:false, | |
sunday:false | |
} | |
const reorder = day => (arr, i = false) => ( | |
i = arr.indexOf(day), | |
[...arr.splice(i), ...arr ] | |
) | |
let saveDayAsBool = [] | |
let days = [] | |
let daysInTheFuture = 28 | |
reorder( 'friday' )( | |
Object.keys(saveDay) | |
).map(val => { | |
saveDayAsBool.push(saveDay[val]) | |
}) | |
for ( let i=0; i <= daysInTheFuture; i++){ | |
if ( !saveDayAsBool[i%7] ) continue; | |
days.push( new Date( Date.now() + 1000*60*60*24*i ) ) | |
} | |
console.dir(days) | |
// Mon Oct 10 2016 12:04:41 GMT-0400 (EDT) | |
// Tue Oct 11 2016 12:04:41 GMT-0400 (EDT) | |
// Wed Oct 12 2016 12:04:41 GMT-0400 (EDT) | |
// Mon Oct 17 2016 12:04:41 GMT-0400 (EDT) | |
// Tue Oct 18 2016 12:04:41 GMT-0400 (EDT) | |
// Wed Oct 19 2016 12:04:41 GMT-0400 (EDT) | |
// Mon Oct 24 2016 12:04:41 GMT-0400 (EDT) | |
// Tue Oct 25 2016 12:04:41 GMT-0400 (EDT) | |
// Wed Oct 26 2016 12:04:41 GMT-0400 (EDT) | |
// Mon Oct 31 2016 12:04:41 GMT-0400 (EDT) | |
// Tue Nov 01 2016 12:04:41 GMT-0400 (EDT) | |
// Wed Nov 02 2016 12:04:41 GMT-0400 (EDT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment