Generate an Acronym
R, 66 63 bytes
function(s)(s=substr(strsplit(s,' |-')[[1]],1,1))[s%in%LETTERS]
Try it online!
-3 bytes thanks to Scarabee
An anonymous function; returns the acronym as a vector c("N","A","T","O")
which is implicitly printed.
For once, this isn't too bad in R! splits on -
or (space)
, takes the first element of each of those, and then returns whichever ones are capitals (LETTERS
is an R builtin with the capital letters), in order.
V, 7 bytes
ÍÕü¼À!õ
Try it online!
Here is a hexdump to prove the byte count:
00000000: cdd5 fcbc c021 f5 .....!.
Explanation:
Í " Search and replace all occurrences on all lines:
" (Search for)
Õ " A non-uppercase letter [^A-Z]
ü " OR
õ " An uppercase letter
À! " Not preceded by...
¼ " A word-boundary
" (implicitly) And replace it with:
" Nothing
This is short all thanks to V's wonderful regex compression.
Python 2, 59 56 bytes
-3 bytes thanks to Lynn
lambda s:[b for a,b in zip(' '+s,s)if'@'<b<'['>a in' -']
Try it online!