title: Get all days of the week given a day
body: <p>I'm trying to make a function to get all the days of the week given the current day. I had a function that i thought was working until i noticed that if the day of the week is near the end of the month, like for example February, i get weird data. Anyone know whats going on and how to fix it?</p>
  <p><a href="https://i.stack.imgur.com/I7dYH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I7dYH.png" alt="Console" /></a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function days(current) {
    var week = new Array();
    // Starting Monday not Sunday 
    var first = ((current.getDate() - current.getDay()) + 1);
    for (var i = 0; i &lt; 7; i++) {
      week.push(
        new Date(current.setDate(first++))
      );
    }
    return week;
  }
  
  var input = new Date(2017, 1, 27);
  console.log('input: %s', input);
  
  var result = days(input);
  console.log(result.map(d =&gt; d.toString()));</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.as-console-wrapper{min-height:100%}</code></pre>
  </div>
  </div>
  </p>