Middle three digits: Difference between revisions

m
→‎{{header|JavaScript}}: (simpler expression for max numeric string length)
m (→‎{{header|JavaScript}}: (simpler expression for max numeric string length))
Line 2,674:
-100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0
],
w = lengthmaximum(map(x => x.toString().length, xs));
maximumBy(
comparing(length),
map(x => x.toString(), xs)
)
);
return (
unlines(map(
Line 2,709 ⟶ 2,704:
// abs :: Num -> Num
const abs = Math.abs;
 
// comparing :: (a -> b) -> (a -> a -> Ordering)
const comparing = f =>
(x, y) => {
const
a = f(x),
b = f(y);
return a < b ? -1 : (a > b ? 1 : 0);
};
 
// drop :: Int -> [a] -> [a]
Line 2,737 ⟶ 2,723:
// even :: Int -> Bool
const even = n => 0 === n % 2;
 
// comparingfoldl1 :: (a -> b)a -> (a) -> [a] -> Ordering)a
const comparingfoldl1 = (f, xs) =>
1 < xs.length ? xs.slice(1)
.reduce((af, x) => xs[0 < f(x, a]) ? x : a, xs[0]);
 
// id :: a -> a
Line 2,757 ⟶ 2,748:
) : Infinity;
 
// maximumBymaximum :: (a ->Ord a -> Ordering) -=> [a] -> a
const maximumBymaximum = (f, xs) =>
0 < xs.length ? (
xs.slicefoldl1(1(a, x) => x > a ? x : a, xs)
.reduce((a, x) => 0 < f(x, a) ? x : a, xs[0])
) : undefined;
 
9,659

edits