I'm developing an app which needs a list of the days of the week, but right now the require("locale").dow() function only accepts a Date object. So I've had to do this:
let daysOfWeek = [];
for (let i = 1; i <= 7; i++) {
daysOfWeek.push(require('locale').dow(new Date(1970, 1, i, 0, 0, 0, 0)); // 1/1/1970 was a Sunday
}
// Result: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
It seems to me it would be more efficient if the dow() function could accept an integer as well (0 = Sunday, 6 = Saturday) because right now it's just calling getDay() on the argument. That way, the code would be simpler:
let daysOfWeek = [];
for (let i = 0; i < 7; i++) {
daysOfWeek.push(require('locale').dow(i);
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'm developing an app which needs a list of the days of the week, but right now the
require("locale").dow()
function only accepts a Date object. So I've had to do this:It seems to me it would be more efficient if the dow() function could accept an integer as well (0 = Sunday, 6 = Saturday) because right now it's just calling
getDay()
on the argument. That way, the code would be simpler:Does this make sense?