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 -----------------------------------------------------
//
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);▼
// a -> maybe f -> maybe n -> String▼
const show = JSON.stringify;▼
// concat :: [[a]] -> [a] | [String] -> String
const concat = xs =>
const unit = typeof xs[0] === 'string' ? '' : [];
return unit.concat.apply(unit, xs);
})()
};▼
const intercalate = (s, xs) => xs.join(s);
// justifyLeft :: Int -> Char -> Text -> Text
Line 722 ⟶ 705:
.substr(0, n)
) : strText;
// map :: (a -> b) -> [a] -> [b]
// show :: Int -> a -> Indented String
null, x.length > 1 ? [x[1], null, x[0]] : x
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
//
const
//
const
▲ xs.slice(0, Math.min(xs.length, ys.length))
▲ .map((x, i) => [x, ys[i]]);
▲ // zip3 :: [a] -> [b] -> [c] -> [(a,b,c)]
▲ 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,
)
);
})();</lang>
|