Minimum numbers of three lists: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: Added a JavaScript version.)
Line 207: Line 207:


// --------------------- GENERIC ---------------------
// --------------------- GENERIC ---------------------

// min :: Ord a => (a, a) -> a
const min = (a, b) =>
// The lesser of a and b.
b < a ? b : a;



// minimum :: Ord a => [a] -> a
// minimum :: Ord a => [a] -> a
Line 212: Line 218:
// The least value of xs.
// The least value of xs.
0 < xs.length ? (
0 < xs.length ? (
xs.slice(1)
xs.slice(1).reduce(min, xs[0])
.reduce((a, x) => x < a ? (
x
) : a,
xs[0]
)
) : null;
) : null;


Line 234: Line 235:


// MAIN ---
// MAIN ---
return main();
return JSON.stringify(main());
})();</lang>
})();</lang>
{{Out}}
{{Out}}