September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,7 +1,6 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
|
||||
// longMonthsStartingFriday :: Int -> Int
|
||||
function longMonthsStartingFriday(y) {
|
||||
return [0, 2, 4, 6, 7, 9, 11]
|
||||
|
|
@ -11,7 +10,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1))
|
||||
|
|
@ -53,5 +51,4 @@
|
|||
},
|
||||
null, 2
|
||||
);
|
||||
|
||||
})();
|
||||
|
|
|
|||
60
Task/Five-weekends/JavaScript/five-weekends-4.js
Normal file
60
Task/Five-weekends/JavaScript/five-weekends-4.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
(() => {
|
||||
// longMonthsStartingFriday :: Int -> [Int]
|
||||
const longMonthsStartingFriday = y =>
|
||||
filter(m => (new Date(Date.UTC(y, m, 1)))
|
||||
.getDay() === 5, [0, 2, 4, 6, 7, 9, 11]);
|
||||
|
||||
// Years -> YearMonths
|
||||
// fullMonths :: [Int] -> [String]
|
||||
const fullMonths = xs =>
|
||||
foldl((a, y) => a.concat(
|
||||
map(m => `${y.toString()} ${[
|
||||
'January', '', 'March', '', 'May', '',
|
||||
'July', 'August', '', 'October', '', 'December'
|
||||
][m]}`, longMonthsStartingFriday(y))
|
||||
), [], xs);
|
||||
|
||||
// leanYears :: [Int] -> [Int]
|
||||
const leanYears = years =>
|
||||
filter(y => longMonthsStartingFriday(y)
|
||||
.length === 0, years);
|
||||
|
||||
// GENERIC ----------------------------------------------------------------
|
||||
|
||||
// A list of functions applied to a list of arguments
|
||||
// <*> :: [(a -> b)] -> [a] -> [b]
|
||||
const ap = (fs, xs) => //
|
||||
[].concat.apply([], fs.map(f => //
|
||||
[].concat.apply([], xs.map(x => [f(x)]))));
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = (m, n) =>
|
||||
Array.from({
|
||||
length: Math.floor(n - m) + 1
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// filter :: (a -> Bool) -> [a] -> [a]
|
||||
const filter = (f, xs) => xs.filter(f);
|
||||
|
||||
// foldl :: (b -> a -> b) -> b -> [a] -> b
|
||||
const foldl = (f, a, xs) => xs.reduce(f, a);
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = (f, xs) => xs.map(f);
|
||||
|
||||
// show :: a -> String
|
||||
const show = x => JSON.stringify(x, null, 2);
|
||||
|
||||
|
||||
// TEST -------------------------------------------------------------------
|
||||
const [lstFullMonths, lstLeanYears] = ap(
|
||||
[fullMonths, leanYears], [enumFromTo(1900, 2100)]
|
||||
);
|
||||
|
||||
return show({
|
||||
number: lstFullMonths.length,
|
||||
firstFive: lstFullMonths.slice(0, 5),
|
||||
lastFive: lstFullMonths.slice(-5),
|
||||
leanYearCount: lstLeanYears.length
|
||||
});
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue