From Dojo Toolkit (a very powerful AJAX toolkit), but should probably go to The Daily WTF

_getAdjustedDay: function(/*Date*/dateObj)
  //summary: used to adjust date.getDay() values to the new values based on the current first day of the week value
  var days = [0,1,2,3,4,5,6];
  if(this.weekStartsOn>0){
    for(var i=0;i<this.weekStartsOn;i++){
      days.unshift(days.pop());
    }
  }
  return days[dateObj.getDay()]; // Number: 0..6 where 0=Sunday
}

That code is inefficient and stupid on so many levels. For example the if statement… you might be aware that 0 < 0 is false.

Yep. I’d prefer something along the lines of

  return (dateObj.getDay() - this.weekStartsOn) % 7;

No arrays were abused during the making of this function.

I always thought PHP programmers were the worst, but apparently some JavaScript “coderz” are up to par.