Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
var last_friday_of_month, print_last_fridays_of_month;
|
||||
|
||||
last_friday_of_month = function(year, month) {
|
||||
var i, last_day;
|
||||
i = 0;
|
||||
while (true) {
|
||||
last_day = new Date(year, month, i);
|
||||
if (last_day.getDay() === 5) {
|
||||
return last_day.toDateString();
|
||||
}
|
||||
i -= 1;
|
||||
}
|
||||
};
|
||||
|
||||
print_last_fridays_of_month = function(year) {
|
||||
var month, results;
|
||||
results = [];
|
||||
for (month = 1; month <= 12; ++month) {
|
||||
results.push(console.log(last_friday_of_month(year, month)));
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
(function() {
|
||||
var year;
|
||||
year = parseInt(process.argv[2]);
|
||||
return print_last_fridays_of_month(year);
|
||||
})();
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
// lastFridaysOfYear :: Int -> [Date]
|
||||
function lastFridaysOfYear(y) {
|
||||
return lastWeekDaysOfYear(y, days.friday);
|
||||
}
|
||||
|
||||
// lastWeekDaysOfYear :: Int -> Int -> [Date]
|
||||
function lastWeekDaysOfYear(y, iWeekDay) {
|
||||
return [
|
||||
31,
|
||||
0 === y % 4 && 0 !== y % 100 || 0 === y % 400 ? 29 : 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
]
|
||||
.map(function (d, m) {
|
||||
var dte = new Date(Date.UTC(y, m, d));
|
||||
|
||||
return new Date(Date.UTC(
|
||||
y, m, d - (
|
||||
(dte.getDay() + (7 - iWeekDay)) % 7
|
||||
)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
// isoDateString :: Date -> String
|
||||
function isoDateString(dte) {
|
||||
return dte.toISOString()
|
||||
.substr(0, 10);
|
||||
}
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1))
|
||||
.map(function (x, i) {
|
||||
return m + i;
|
||||
});
|
||||
}
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
function transpose(lst) {
|
||||
return lst[0].map(function (_, iCol) {
|
||||
return lst.map(function (row) {
|
||||
return row[iCol];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var days = {
|
||||
sunday: 0,
|
||||
monday: 1,
|
||||
tuesday: 2,
|
||||
wednesday: 3,
|
||||
thursday: 4,
|
||||
friday: 5,
|
||||
saturday: 6
|
||||
}
|
||||
|
||||
// TEST
|
||||
return transpose(
|
||||
range(2012, 2016)
|
||||
.map(lastFridaysOfYear)
|
||||
)
|
||||
.map(function (row) {
|
||||
return row
|
||||
.map(isoDateString)
|
||||
.join('\t');
|
||||
})
|
||||
.join('\n');
|
||||
})();
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
|
||||
// ------------ LAST FRIDAY OF EACH MONTH ------------
|
||||
|
||||
// lastWeekDaysOfYear :: Int -> Int -> [Date]
|
||||
const lastWeekDaysOfYear = iWeekDay =>
|
||||
y => {
|
||||
const isLeap = n => (
|
||||
(0 === n % 4) && (0 !== n % 100)) || (
|
||||
0 === y % 400
|
||||
);
|
||||
|
||||
return [
|
||||
31, isLeap(y) ? 29 : 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
]
|
||||
.map((d, m) =>
|
||||
new Date(Date.UTC(
|
||||
y, m, d - ((
|
||||
new Date(Date.UTC(
|
||||
y, m, d
|
||||
))
|
||||
.getDay() + (7 - iWeekDay)
|
||||
) % 7)
|
||||
))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const days = {
|
||||
sunday: 0,
|
||||
monday: 1,
|
||||
tuesday: 2,
|
||||
wednesday: 3,
|
||||
thursday: 4,
|
||||
friday: 5,
|
||||
saturday: 6
|
||||
};
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
const main = () =>
|
||||
transpose(
|
||||
enumFromTo(2015)(2019)
|
||||
.map(lastWeekDaysOfYear(days.friday))
|
||||
)
|
||||
.map(
|
||||
row => row.map(isoDateString).join("\t")
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
|
||||
// ---------------- GENERIC FUNCTIONS ----------------
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = m =>
|
||||
n => Array.from({
|
||||
length: 1 + n - m
|
||||
}, (_, i) => m + i);
|
||||
|
||||
|
||||
// isoDateString :: Date -> String
|
||||
const isoDateString = dte =>
|
||||
dte.toISOString()
|
||||
.substr(0, 10);
|
||||
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
const transpose = rows =>
|
||||
// The columns of the input transposed
|
||||
// into new rows.
|
||||
0 < rows.length ? rows[0].map(
|
||||
(x, i) => rows.flatMap(
|
||||
v => v[i]
|
||||
)
|
||||
) : [];
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue