Middle three digits: Difference between revisions
Content deleted Content added
m →{{header|JavaScript}}: (simpler expression for max numeric string length) |
|||
Line 2,674: | Line 2,674: | ||
-100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0 |
-100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0 |
||
], |
], |
||
w = |
w = maximum(map(x => x.toString().length, xs)); |
||
maximumBy( |
|||
comparing(length), |
|||
map(x => x.toString(), xs) |
|||
) |
|||
); |
|||
return ( |
return ( |
||
unlines(map( |
unlines(map( |
||
Line 2,709: | Line 2,704: | ||
// abs :: Num -> Num |
// abs :: Num -> Num |
||
const abs = Math.abs; |
const abs = Math.abs; |
||
⚫ | |||
⚫ | |||
(x, y) => { |
|||
const |
|||
a = f(x), |
|||
b = f(y); |
|||
return a < b ? -1 : (a > b ? 1 : 0); |
|||
}; |
|||
// drop :: Int -> [a] -> [a] |
// drop :: Int -> [a] -> [a] |
||
Line 2,737: | Line 2,723: | ||
// even :: Int -> Bool |
// even :: Int -> Bool |
||
const even = n => 0 === n % 2; |
const even = n => 0 === n % 2; |
||
⚫ | |||
⚫ | |||
1 < xs.length ? xs.slice(1) |
|||
⚫ | |||
// id :: a -> a |
// id :: a -> a |
||
Line 2,757: | Line 2,748: | ||
) : Infinity; |
) : Infinity; |
||
// |
// maximum :: Ord a => [a] -> a |
||
const |
const maximum = xs => |
||
0 < xs.length ? ( |
0 < xs.length ? ( |
||
foldl1((a, x) => x > a ? x : a, xs) |
|||
⚫ | |||
) : undefined; |
) : undefined; |
||