Skip to content

Instantly share code, notes, and snippets.

@amosrivera
Last active January 3, 2016 07:29
Show Gist options
  • Select an option

  • Save amosrivera/8430213 to your computer and use it in GitHub Desktop.

Select an option

Save amosrivera/8430213 to your computer and use it in GitHub Desktop.
Returns an array of the previous 7 days.
// Returns an arrary with the name of the previous seven days (?)
var getPreviousWeek = function(){
// get day index monday => 0, tuesday => 1, ...
var today = (new Date().getDay()-1);
//0 index based array, monday => 0, tuesday => 1 and so on
var days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
// range returns [1, 2, 3, 4, 5, 6, 7]
return days.slice(today).concat(days.slice(0,today))
}
@amosrivera
Copy link
Author

Hm.. Just splitting the array and then appending at the right index should do..

@paulomcnally
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment