Given a weekday and the day of the month it occurs, can I get its ordinal position in constant time?
问题 Say I'm given a date, from which I can get its day of the month and day of the week. For example (in Javascript): var d = new Date(1316038581772); // Wed Sep 14 2011 12:16:21 GMT-1000 var dayOfWeek = d.getDay(); // 3 - Wednesday var dayOfMonth = d.getDate(); // 14 - Day of month I'm looking for a value n such that this date is the n th day of the week in the month. In this case, I'm looking for n=2 , for the 2nd Wednesday in September 2011. The naive algorithm would be to find the first