Find the largest and the smallest number in an array
JavaScript (ES6), 54 56
Edit 2 bytes saved thx @Neil
Note: x===+x
is true if and only if x
is a number
a=>[Math.max(...a=a.filter(x=>x===+x)),Math.min(...a)]
Pyth, 14 11 10 bytes
hM_BS^I#1Q
Try it online. Test suite.
Explanation
Q
: evaluated input#
: filter that on:I
: the value being the same after:^…1
raising it to power 1
S
: sort that_B
: create array[previous, reversed(previous)]
hM
: take first item of each item of that
The hardest part is to golf the removal of strings, which currently takes 4 bytes. The current approach works due to ^<str>1
taking the first Cartesian power of the sequence (basically, the list of the string's characters), but ^<int>1
is just the identity function.
Seriously, 9 6 bytes
,ì;M@m
Try It Online
How it works
, Read list input
ì Remove everything but numbers from it
; Make a copy
m Extract its min value
@M Extract the other one's max value
Implicit output (max then min)