Chinese zodiac: Difference between revisions

→‎JavaScript ES6: Updated primitives, and adjusted test to always include current year
(→‎{{header|AppleScript}}: Updated primitives)
(→‎JavaScript ES6: Updated primitives, and adjusted test to always include current year)
Line 686:
// GENERIC FUNCTIONS -----------------------------------------------------
 
// zipchars :: [a] -> [b]String -> [(a,b)Char]
const zip = (xs, ys) =>
xs.slice(0, Math.min(xs.length, ys.length))
.map((x, i) => [x, ys[i]]);
 
// zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]
const zip3 = (xs, ys, zs) =>
xs.slice(0, Math.min(xs.length, ys.length, zs.length))
.map((x, i) => [x, ys[i], zs[i]]);
 
// words, chars :: String -> [String]
const words = s => s.split(/\s+/);
const chars = s => s.split('');
 
// quot Num a => a -> a -> Int
const quot = (m, n) => Math.floor(m / n);
 
// show ::
// (a -> String) f, Num n =>
// a -> maybe f -> maybe n -> String
const show = JSON.stringify;
 
// concat :: [[a]] -> [a] | [String] -> String
const concat = xs => {
if (xs.length > 0 ? (() => {
const unit = typeof xs[0] === 'string' ? '' : [];
return unit.concat.apply(unit, xs);
})() else return: [];
 
};
// aintercalate ->:: maybe fString -> maybe n[a] -> String
const intercalate = (s, xs) => xs.join(s);
 
// justifyLeft :: Int -> Char -> Text -> Text
Line 722 ⟶ 705:
.substr(0, n)
) : strText;
 
// map :: (a -> b) -> [a] -> [b]
const wordsmap = s(f, xs) => sxs.splitmap(/\s+/f);
 
// quot Num:: a => aInt -> aInt -> Int
const quot = (mn, nm) => Math.floor(mn / nm);
 
// show :: Int -> a -> Indented String
// words, charsshow :: Stringa -> [String]
const zip3show = (xs, ys, zs...x) =>
const show = JSON.stringify;.apply(
null, x.length > 1 ? [x[1], null, x[0]] : x
} );
 
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
 
// intercalatewords :: String -> [aString] -> String
const intercalatewords = (s, xs) => xss.joinsplit(/\s+/);
 
// mapzip :: ([a] -> [b)] -> [(a] -> [,b)]
const mapzip = (fxs, xsys) => xs.map(f);
xs.slice(0, Math.min(xs.length, ys.length))
.map((x, i) => [x, ys[i]]);
 
// zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]
const zipzip3 = (xs, ys, zs) =>
xs.slice(0, Math.min(xs.length, ys.length, zs.length))
.map((x, i) => [x, ys[i], zs[i]]);
 
// TRADITIONAL STRINGS ---------------------------------------------------
Line 805 ⟶ 807:
return intercalate(
'\n\n',
map(
map(showYear, [1935, 1938, 1968, 1972, 1976, 1984, 2017])
showYear,
map(showYear, [1935, 1938, 1968, 1972, 1976, 1984, 2017]new Date().getFullYear()]
)
);
})();</lang>
9,655

edits