I want to compute some number for each given day. The actual number does not matter, it should just be somewhat different but it must be stable.
So I have done the following so far:
now = new Date();
begin_of_week = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 1);
for (idx in [0, 1, 2, 3, 4]) {
seed = parseInt(idx)
+ begin_of_week.getFullYear() * 400,
+ begin_of_week.getMonth() * 31,
+ begin_of_week.getDate();
// ...
}
I expect that this gives me some seed
for each day of the week from Monday to Friday. However, I different numbers for the days, but I now have the same numbers as last week.
JavaScript's type system is a mystery to me. I would expect that all those are int
and they just get added up. It makes a difference whether I put the idx
at the beginning or the end of the chain. And the parseInt
, which should do nothing, actually changes the results.
What is going on here? How can I just add those numbers?