g | x | w | all
Bytes Lang Time Link
084Tcl181222T092330Zdavid
017Raku Perl 6 rakudo241213T164017Zxrs
034AWK241112T190309Zxrs
033ARBLE240902T055508ZATaco
007UiuaSBCS240829T060733ZEurope20
026Zsh240817T113257Zroblogic
003Japt h171220T140948ZShaggy
006Uiua231117T222201Zchunes
033Noulith231118T012553Zbigyihsu
002Thunno 2230616T171318ZThe Thon
007Factor221013T030326Zchunes
002Vyxal221013T025125ZDialFros
7064Lua181222T084835Zcyclamin
021Kotlin181221T195319Zsnail_
015jq r181221T192012Zuser4180
071sed 4.2.2 rz180108T183342Zuser4180
004Pyth171220T135126ZMr. Xcod
009Attache180325T143104ZConor O&
063C++ gcc180324T081151ZKarl Nap
036dc171220T162015Zcab404
044Bash171221T033421Zuser1775
007Add++180307T214833Zcaird co
031R + pryr171220T103847ZNofP
016APL171221T054008Zrmoro
057SNOBOL4 CSNOBOL4171221T164256ZGiuseppe
013Coconut180210T125120Zovs
024Perl180211T222433ZTon Hosp
020V171223T115304Zoktupol
069Prolog SWI171220T113224ZEmigna
024APL NARS180108T105824Zuser5898
3642EXCEL171220T113031Zpbeentje
041Javascript ES5171221T173102ZJack
069PHP171223T031329ZKrzysiu
040Google Sheets180102T192707ZTaylor R
059PHP180102T105048ZTitus
168Imperative Tampio171220T112747Zfergusq
020Ruby171222T084616ZG B
00305AB1E171227T185432ZEmigna
035Haskell171220T104448Ztotallyh
023Python171220T102025ZNeil
004Jelly171224T033857Zuser2027
022Scratch 2.0171224T051153ZMustache
003Husk171223T224011Zბიმო
032Common Lisp171223T191515ZRenzo
008J171220T115143ZGalen Iv
019Stacked171222T232525ZConor O&
029F# .NET Core171222T162225ZAaron M.
030Röda171220T113629Zfergusq
160Scratch171222T025158Zfede s.
125C++171221T151744ZToby Spe
045Bash171221T150518Znxnev
110Racket171220T155024ZDaniel L
038JavaScript Node.js171220T102652ZLiefdeWe
5770Java 8171221T065434ZChristop
038Funky171220T225532ZATaco
024MY171220T222312ZAdalynn
072PHP171220T214921ZAlan Ond
073Rust171220T204848ZHåv
038Perl 5171220T202111ZXcali
024Julia 0.6171220T194214ZLukeS
011APL+WIN171220T191752ZGraham
029Mathematica171220T190340ZLegionMa
033Octave171220T145800ZLuis Men
nan171220T180213ZBrad Gil
067Java OpenJDK 8171220T150904ZLucy Ste
055Standard ML MLton171220T144513ZLaikoni
009K oK171220T111656Zmkst
024PowerShell171220T134414ZAdmBorkB
009APL Dyalog Unicode171220T124246ZAdá
nanC#171220T102105ZLiefdeWe
054Swift171220T105606ZEndenite

Tcl, 93 84 bytes

Second proc lost its return thx to @sergiol

proc c a\ b {expr [string le $a]<[string le $b]}
proc L l {lindex [lsort -c c $l] 0}

Try it online!

Quite disappointed by the score, should/could be better. Thought about this one-proc version:

proc L l {
 set m  [lmap e $l {regsub -all . $e 1}]
 return [lindex $l [lsearch $m [expr max([join $m ,])]]]
}

but it's longer. See also @sergiol 2nd comment to another single-proc version.

Raku (Perl 6) (rakudo), 17 bytes

{@_.max: *.chars}

Attempt This Online!

{@_.     # split list
max:     # find the max of each
*.chars} # based on num of chars

AWK, -F '' -vRS=" " 34 bytes

{NF-1>length(x)&&x=$0}END{print x}

To test:

awk -F "" -vRS=" " '{NF-1>length(x)&&x=$0}END{print x}' <<< "tiny small bigger biggest"

{NF-1>         # length of current word
length(x)      # length of longest
&&x=$0}        # set longest
END{print x}   # print when done 

ARBLE, 33 bytes

a/select(1+lt(len(b),len(c)),b,c)
a/select(1+lt(len(b),len(c)),b,c)
a/                                -- Fold the first input over the given function
  select(1+                 ,b,c) -- If the condition is 1, return the second argument. Otherwise, return the first.
           lt(len(b),len(c))      -- Is the length of the first argument less than the length of the second

Try it online!

Actually surprised how hard this was for ARBLE, as it doesn't have a maxby or sort function.

UiuaSBCS, 9 7 bytes

⊏⊢⍖≡◇⧻.

Try it here!

Both the input and output is □ boxed. Does not work on empty arrays.

Explanation

Code      | Desc                    | Stack
⊏⊢⍖≡◇⧻. |                          | {"tiny" "small" "bigger" "biggest"}
    ≡◇⧻. | array of lengths         | {"tiny" "small" "bigger" "biggest"} [4 5 6 7]
  ⍖     | index of descending sort | {"tiny" "small" "bigger" "biggest"} [3 2 1 0]
 ⊢       | first element            | {"tiny" "small" "bigger" "biggest"}
⊏        | select that index        | ⌜biggest⌟

Zsh, 28 26 bytes

for i;<<<$i>$i;ls -S|sed q

Try it online! 28b

Write each argument (<<<$i) to a file also named (>$i). List directory (ls -S) sorted by size. Take the top result.

A direct port of the bash solution is 29 bytes:

for b;(($#b>$#a))&&a=$b;<<<$a

Japt -h, 5 3 bytes

ÔñÊ

Try it

Reverse, sort by length and output the last element.

Alternatively ...

Japt -g, 3 bytes

üÊÌ

Try it

Sort & group by length, get the last element and output the first element.

Uiua, 6 bytes

⊡⊢⍖⍚⧻.

Try it!

⊡⊢⍖⍚⧻.
     .  # duplicate
   ⍚⧻   # lengths
 ⊢⍖     # index of maximum
⊡       # pick

Noulith, 33 bytes

\l->l find\w->w.len==max(l map len)

Try it online!

Explanation

\l->                                # lambda, taking in a list of strings
    l find                          # find in `l`...
          \w->                      # some word `w` such that...
              w.len                 # the length of `w`...
                   ==               # is equal to...
                     max(l map len) # the longest `w` in `l`

Thunno 2, 2 bytes

ØG

Attempt This Online!

Built-in.

Factor, 7 bytes

longest

Try it online!

Builtin

Vyxal, 2 bytes

ÞG

Try it Online!

Lua, 70 64 bytes

function f(a,...)x=...and f(...)return x and#x>#a and x or a end

Try it online!

x is set to the second argument if that is falsy, otherwise the longest of the second argument and up. The function returns x if it is truthy and longer than the first argument, else the first argument.

No type-checking, so works not only for a sequence of strings, but for sequences containing tables, or anything with a __len metamethod that returns a number. For instance f("tiny", {1, 2, 3, 4, 5}, debug.setmetatable(6, { __len = function (self) return self end })) returns 6.

This technically breaks the rule of operating on an array (in Lua, a table) because it operates on an argument list, but operating on a table seemed more complicated (table.sort is not stable). A table can be unpacked into the function: f(table.unpack { 'oh', 'one', 'two' }).

Kotlin, 21 bytes

{it.maxBy{it.length}}

Try it online!

jq -r, 19 15 bytes

Golfed 4 bytes after learning min_by is a builtin.

min_by(-length)

Try it online!

(Without -r the output string is surrounded with "s.)

sed 4.2.2 -rz, 71 72 83 bytes

h
:
s/^.//gm
/[^\n]{2}/t
:b
/^\n/{s/.//
x
s/^[^\n]*.//
x}
tb
x
s/\n.*//

Try it online!

This was a fun challenge seeing as sed did not have any builtin sort functions. The program works as follows:

Pyth, 4 bytes

h.Ml

Test suite.

Explanation
h.Ml   | Program
h.MlZQ | With implicit variables filled in
-------+--------------------------------------------------------------------
h      | First element of
 .M  Q | The list of elements from the input list with the maximal value for
   lZ  | The length of the element

Attache, 9 bytes

MaxBy&:`#

Try it online!

This is simply bonding the size operator (`#) to the left of MaxBy. This is equivalent to:

f[x] := MaxBy[Size, x]

...which selects the first element with the largest size in x.

C++ (gcc), 65 63 bytes

Accepts any container of std::string and returns via reference.

[](auto&c,auto&r){r=c[0];for(auto x:c)r=x.size()>r.size()?x:r;}

Try it online!

If you are tolerant to output, there is a 58 byte solution which alters the input list and copies the longest string to the first element:

[](auto&c){for(auto x:c)c[0]=x.size()>c[0].size()?x:c[0];}

dc, 39 38 36 bytes

0sl[slssdd]sG[dZdll!>Gooz0<M]dsMxlsp

Try it online!

Edit: -1 byte, filling up empty space by 'd' instead

Edit: -2 bytes, thanks @brhfl for suggestion!

Bash, 44 bytes

IFS=$'\n';egrep -m1 .{`wc -L<<<"$*"`}<<<"$*"

Try it online!

Add++, 7 bytes

L,bU«bL

Try it online!

More interesting, 32 byte version:

L,vbU§bLdbLBkÞ{g}@
D,g,@,bLBK=

Try it online!

How they work

L,	; Create a lambda function
	; Example argument:         		[["two" "one" "abc" "no"]]
    bU	; Evaluate as list; 			STACK = ['two' 'one' 'abc' 'no']
    «bL	; Take the value with the max length;	STACK = ['two']

And the 32 byte version:

L,		; Create a lambda function
		; Example argument: 		['["two" "one" "no"]']
	vbU	; Evaluate;		STACK = ['two' 'one' 'no']
	§bL	; Sort by length;	STACK = ['no' 'two' 'one']
	dbLBk	; Save length;		STACK = ['no' 'two' 'one']	REGISTER = 3
	Þ{g}	; Filter by 'g';	STACK = ['two' 'one']
	@	; Reverse;		STACK = ['one' 'two']
		; Implicitly return the top element:   'two'

D,g,@,		; Create a function 'g'
		; Example argument:		['two']
	bL	; Length;		STACK =	[3]
	BK=	; Equal to register;	STACK = [1]

R + pryr, 31 bytes

[-2 bytes thanks to Scrooble]

pryr::f(x[order(-nchar(x))][1])

Try it online!


R, 33 bytes

function(x)x[order(-nchar(x))][1]

Try it online!

APL -- 23 16 bytes

a←{((⍴¨⍵)⍳(⌈/(⍴¨⍵)))⌷⍵}

Thanks to everyone for all of your great suggestions and encouragement!

a←{⍵⌷⍨(⍴¨⍵)⍳⌈/⍴¨⍵}

Usage:

a 'duck' 'duck' 'goose'
  'goose'

Explanation:

gets length of each vector of characters (string) then uses maximum as an index. I just started APL 20 min ago so I am sorry if this is a stupid way to do it.

Try it Online!

(edited for clarity)

SNOBOL4 (CSNOBOL4), 63 57 bytes

I	M =LT(SIZE(M),SIZE(X)) X
	X =INPUT	:S(I)
	OUTPUT =M
END

Try it online!

Input is on stdin and output on stdout.

Roughly translates to the following pseudocode:

while input exists
 x = input
 if length(m) < length(x)
  m = x
end
return m

Coconut, 15 13 bytes

max$(key=len)

Try it online!

Perl, 24 bytes

Includes +1 for p

Give words as lines on STDIN

perl -pe '$;[y///c]//=$_}{$_=pop@'
one
two 
no
^D

V, 27 23 21 20 bytes

Í./_
ÚGYu/"
uYHVGp

Try it online!

Explanation:

Í./_         In every line, replace every character by _
Ú            Sort alphabetically. Cursor ends up in first line
 GY          Go to last line, copy it
   u         Undo sort
    /"       Search for string in register " (the one that was just copied). Non-printable character is <C-r>
u            Undo replace, go to last cursor position. Non-printable character is <C-o> (thanks, Cows quack)
  Y          Copy line
   HVG       Go to first line, select all lines until last line
      p      Paste copied line into selection

Hexdump:

00000000: cd2e 2f5f 0ada 4759 752f 1222 0a75 0f59  ../_..GYu/.".u.Y
00000010: 4856 4770                                HVGp

Prolog (SWI), 98 92 72 69 bytes

The top level predicate is *.

X/Y:-atom_length(X,Y).
[A]*A.
[A,B|L]*Z:-A/X,B/Y,Y>X,[B|L]*Z;[A|L]*Z.

Try it online!

Explanation

The first row defines the dyadic predicate / to be a short for atom_length/2which is true if the first argument's length is the second argument. This saves us 3 bytes over using atom_length twice.

Our main predicate is defined as the dyadic * where the first argument is a list and the second argument the longest element of that list.

The second row is our base case which states that the longest element of a one element list is that element.

The third row states that for a list with at least 2 elements, the longest element is:

If the length of the second element is longer than the first element, the longest element is in the list without the first element.

Otherwise the longest element is in the list without the second element.

APL NARS, 10 chars, 24 bytes

{⍵[↑⍒⍴¨⍵]}

note in the test, that: 'uno' it is not one array of array, so the array of correct deep is ,⊂'uno' instead

⎕fmt  ,⊂'uno'    
  ┌1─────┐
  │┌3───┐│
  ││ uno││
  │└────┘2
  └∊─────┘

so in the test g fail for 'uno'

g←{⍵[↑⍒⍴¨⍵]}
g 'uno'
  u

but not fail for the correct type of input

g ,⊂'uno'
  uno
g 'uno' 'quattro' 'cinque'
  quattro
⎕fmt  g ,⊂''
  ┌───┐
  │┌0┐│
  ││ ││
  │└¯┘2
  └∊──┘

if the community think this is one too much big limitation: than there is the 18 chars solution

{1=≡⍵:⍵⋄∊⍵[↑⍒⍴¨⍵]} 

that evade the problem in the first test calculate the deep of input

f←{1=≡⍵:⍵⋄∊⍵[↑⍒⍴¨⍵]}     
f 'uno'
  uno
f 'uno' 'quattro' 'cinque'
  quattro

The problem of the input type of one Char in Apl as 'a' (it is consider from interpreter one char). We can transform that in one array of array of char, or one type list of arrays of deep 2 write ,⊂,'a'; so g ,⊂,'a' should return the correct answer of type array of array length 1

EXCEL, 36 42 bytes

=INDEX(A:A,MATCH(MAX(LEN(A:A)),LEN(A:A),))

Entered as an array formula (ctrl-shift-enter). The input array should be entered in column A.

The formula returns the first match with maximum length.

Depending on your region settings, substitute , with ;; the code length remains unchanged. Of the 16 languages listed here, English function names are the shortest for this formula.

Explanation:

=                                          - return
 INDEX(                                  ) - the item of
       A:A                                 - the input
          ,                                - at
           MATCH(                       )  - the position of
                                       ,   - the first exact match of
                 MAX(        )             - the maximum of
                     LEN(   )              - the array of lengths of
                         A:A               - the input
                              ,            - in
                               LEN(   )    - the array of lengths of
                                   A:A     - the input

Javascript ES5, 41 bytes

Since there was already a solution using sort...

Try it online

a=>a.reduce((x,y)=>x.length>=y.length?x:y)

PHP, 69 bytes

usort($x,function($a,$b){return strlen($b)<=>strlen($a);});echo$x[0];

Not a trick or nice golfing, just sorting array by string length and then outputting the first element.

Google Sheets, 40 Bytes

Anonymous worksheet function that takes input from range A:A and outputs to the calling cell

=Index(A:A,Match(Max(Len(A:A)),Len(A:A),

PHP, 59 bytes

while($n=strlen($s=$argv[++$i]))$n>$e&&$e=$n+!$r=$s;echo$r;

takes words as separate command line arguments. Run with -nr or try it online.

Imperative Tampio, 168 bytes

Listan x on riippuen siitä,onko sen ensimmäisen alkion pituus suurempi tai yhtä suuri kuin sen jokaisen alkion pituus,joko sen ensimmäinen alkio tai sen hännän x.

Online version

Ungolfed:

Listan pisin alkio on riippuen siitä, onko sen ensimmäisen alkion pituus suurempi tai yhtä suuri kuin sen jokaisen alkion pituus, joko

  • sen ensimmäinen alkio tai
  • sen hännän pisin alkio.

Online version

The only golfing opportunity this has is to replace pisin alkio (meaning "the longest element") with x.

Translation:

The longest item in a list is, depending on whether the length of the first item is greater or equal to the length of each element in the list, either

  • the first item in the list, or
  • the longest item in the tail of the list.

Ruby, 21 20 bytes

->s{s.max_by &:size}

Try it online!

Trivial solution, thanks Snack for -1 byte

05AB1E, 3 bytes

Réθ

Try it online!

Explanation

R     # reverse
 é    # sort by length
  θ   # get the last element

Haskell, 35 bytes

-3 bytes thanks to Zgarb.

foldl1(!)
a!b|(a<$a)<(a<$b)=b|1<2=a

Try it online!

I like this code. You know why? Because Haskell supports much more elegant solutions with functions from random libraries.

maximumBy(compare`on`length).reverse

That's friggin' readable! Except, it's not valid.

import Data.List
import Data.Function
maximumBy(compare`on`length).reverse

If it weren't for the imports, this would've been a perfect submission to get all the upvotes. :P

(Also, this uses one golfing tip and it uses a fold.)

Python, 23 bytes

lambda a:max(a,key=len)

Try it online!

Jelly, 4 bytes

LÐṀḢ

Try it online!

Maximum (ÐṀ) by length (L). Take Head ().


Jelly, 4 bytes

ṚLÞṪ

Try it online!

Reverse. Sort by length. Take tail (last element).

Scratch 2.0, 22 blocks

Accepts input by pressing see inside on the project page and manually adding and removing items from list.

Project here. Flash required to run and view, apologies.

All blocks were counted including nested ones. Not sure how I'd count bytes with this language unless you want the length of the JSON.

Husk, 3 bytes

►L↔

Try it online!

Explanation

  ↔  -- reverse the list (such that the first gets picked in case of a tie)
►L   -- find maximum by length

Common Lisp, 32 bytes

(elt(sort(read)'> :key'length)0)

Try it online!

J, 19, 11, 10 8 bytes

0{>\:#@>

Try it online!

Thanks to streetster for the hint!

-1 byte thanks to FrownyFrog!

-2 bytes thanks to Conor O'Brien

How it works:

    (  #@>) - unbox each string and find its length
     \:     - sort down the list of strings according to the lengths
0{::        - take and unbox the first string

Try it online!

Stacked, 19 bytes

[:$#'"!:MAX index#]

Try it online!

Explanation

[:$#'"!:MAX index#]
[                 ]   anonymous function, takes input as list of strings
 :$  "!               on each member:
   #'                   get the length
            index     get the index of...
       :MAX             the maximum length
                 #    and obtain the respective member in the array.

Alternatives

19 bytes: [[#'\#'-]sortby 0#]

24 bytes: [$#'"!:sorted index#_1#]

F# (.NET Core), 29 bytes

 Seq.maxBy <| fun s->s.Length

Try it online!

Explanation

Through partial application of Seq.maxBy, returns a function (string seq -> string)

Röda, 30 bytes

{enum|[[#_,-_,_1]]|max|_|tail}

Try it online!

Explanation:

{
 enum|         /* For each element, push its index to the stream */
 [[#_,-_,_1]]| /* For each element and index, push [length, -index, element] */
 max|          /* Find the greatest element */
 _|            /* Flat the list in the stream */
 tail          /* Return the last item in the stream */
}

Alternative 30 bytes:

{enum|[[#_,-_,_1]]|max|[_[2]]}

Try it online!

Scratch 27 17 170 160

the code picture

It expects a global (attached to all sprites, to be more precise) list of strings called mylist. After clicking the green flag, the longest word will be left in the variable w.

I think this is the link

when gf clicked
set[w]to(item[1]of[mylist
set[i]to[0
repeat(length of[mylist
change[i]by(1
set[m]to(item(i)of[mylist
if<(m)>(w)>then
set[w]to(m
end
end
stop[all

Counting as per this meta.

C++, 125 bytes

Accepts input as a pair of iterators; returns an iterator to the longest string. The array must not be empty (i.e. the iterators must be different).

#include<algorithm>
template<class I>I f(I a,I b){return std::max_element(a,b,[](auto&a,auto&b){return a.size()<b.size();});}

Demo

#include <string>
#include <iostream>
#include <iterator>
int main()
{
    std::string strings[] = { "Programming", "Puzzles", "and", "Code", "Golf" };

    std::cout << *f(std::begin(strings), std::end(strings)) << std::endl;
}

The definition of std::max_element() guarantees that

If several elements in the range are equivalent to the greatest element, returns the iterator to the first such element.

Bash, 45 bytes

a=;for b;do((${#b}>${#a}))&&a=$b;done;echo $a

Try it online!

Racket, 160 bytes 110 bytes

Try it online! First time contributing, advice appreciated!

(define(m a)(if(>(length a)1)(if(>=(string-length(car a))(string-length(m(cdr a))))(car a)(m(cdr a)))(car a)))

Ungolfed

(define (m a)
    (if (> (length a) 1)
        (if (>= (string-length (car a)) (string-length (m (cdr a))))
            (car a)
            (m (cdr a))
        )
        (car a)
    )
)

Updated solution based on feedback

JavaScript (Node.js), 38 bytes

Try it online!

a=>a.sort((a,b)=>a.length<b.length)[0]

Java 8, 57 bytes (70 bytes)

By the power of streams, my java answer shall be the shortest

Arrays.stream(a).max(Comparator.comparing(String::length))

Honestly I don't know if I cheated with that answer because I don't return anything but you could use that line of code. If we really want to return stuff then it's a bit longer.

Thanks to LukeStevens for pointing out to use lambdas to be more golfy.

w->Arrays.stream(w).max(Comparator.comparing(String::length)‌​).get()

Funky, 38 bytes

a=>a[(v=a::map@#)::find(math.max...v)]

Explained

a=>a[(v=a::map@#)::find(math.max...v)]
        a::map@#                        $ Create a list of the lengths of the input's strings.
      v=                                $ And assign it to v.
     (          )::find(            )   $ Find the first index in this list that equals...
                        math.max...v    $ The largest value of v, eg. the length of the longest string.
   a[                                ]  $ Get the value at that position.

Try it online!

MY, 24 bytes

1ω74ǵ'ƒ⇹(ω74ǵ'ƒ⇹(⍐=⍸@ω@←

Try it online!

How?

1ω74ǵ'ƒ⇹(ω74ǵ'ƒ⇹(⍐=⍸@ω@←
                       ← = Output ...
                      ω  = ... the input ...
                       @ = ... at ...
1                    @   = ... the first ...
                   ⍸     = ... truthy index of ...
 ω74ǵ'ƒ⇹(                = ... the length of each element of the input's ...
                  =      = ... equality with ...
         ω74ǵ'ƒ⇹(⍐       = ... the maximum length.
          

PHP, 72 bytes

array_reduce($a,function($c,$i){return (strlen($i)>strlen($c))?$i:$c;});

Rust, 73 bytes

|mut x:Vec<String>|{x.sort_by(|a,b|b.len().cmp(&a.len()));x[0].clone()}

Very simple code, that can probably be golfed at least a little more. The fact that i had to use String instead of &str, just for the return value, bugs me alot. (I could have used a .to_string() method, but that wouldve added 2 bytes.)

Try it online!

Perl 5, 38 bytes

say((sort{$a=~y///c<=$b=~y///c}<>)[0])

Try it online!

Julia 0.6, 24 bytes

!s=s[indmax(length.(s))]

Try it online!

APL+WIN, 11 bytes

s[↑⍒∊⍴¨s←⎕]

Prompts for screen input in the form 'abc' 'defg' hijklm'

Mathematica, 29 bytes

#&@@#~MaximalBy~StringLength&

Pure function. Takes a list of strings as input and returns a string as output. #~MaximalBy~StringLength finds the longest strings in the list and #&@@ selects the first instance.

Octave, 33 bytes

@(x)x{[~,p]=max(cellfun(@nnz,x))}

Input is a cell array of strings.

Try it online!

Explanation

cellfun(@nnz,x) applies the nnz function (number of nonzeros) to each string in the input array x. For ASCII strings, nnz is equivalent to numel (number of elements), but shorter. The result is a numeric array with the string lengths.

Then, [~,]=max(...) gives the index of the first maximum in the array of string lengths. The result is used as a curly-brace index into x to obtain the corresponding string.

Perl 6,  14  13 bytes

*.max(*.chars)

Try it

*.max(&chars)

Try it

Java (OpenJDK 8), 67 bytes

Another submission in my favourite language! (read: the only one I know).
This doesn't work with an empty array, but that's fine.

Golfed

w->{for(String y:w)if(y.length()>w[0].length())w[0]=y;return w[0];}

Ungolfed

for(String y:w)                           // Loops through all Strings
    if(y.length()>w[0].length())          // If the String is longer than the first String 
                                w[0]=y;   // Store it as the first string.
return w[0];                              // Return the first String.

Try it online!

Standard ML (MLton), 55 bytes

fun&(s::r)=foldl(fn(%,$)=>if size% >size$then%else$)s r

Try it online! Example usage: & ["abc","de","fgh"] yields "abc".

Ungolfed:

fun step (current, longest) = 
    if size current > size longest 
    then current 
    else longest

fun longestString (start :: list) = foldl step start list
  | longestString nil = raise Empty

Try it online!

K (oK), 9 bytes

*x@>#:'x:

Try it online!

Example:

*x@>#:'x:("edur";"oot";"taht")
"edur"

Explanation

*x@>#:'x: / solution
       x: / store input in variable x
    #:'   / count (#:) each (')
   >      / sort descending
 x@       / apply indices to x
*         / take the first one

Notes:

Undeleted as this is classed as non-trivial, despite being basically 5 steps (would be if written as the function {*x@>#:'x}).

PowerShell, 24 bytes

($args[0]|sort l* -d)[0]

Try it online!

Takes input $args[0], pipes that to Sort-Object based on length in -descending order. Then takes the [0]th one thereof. Since sort is stable, this takes the first element in case of a tie.

APL (Dyalog Unicode), 9 bytesSBCS

⊢⊃⍨∘⊃∘⍒≢¨

Try it online!

 from the argument,

⊃⍨ pick the element with the index which is the

 first of the

 indices in descending order of the

≢¨ lengths of each

C#, 43 + 18 = 61 bytes

Try it online!

a=>a.OrderByDescending(x=>x.Length).First()

Swift, 54 bytes

{($0 as[String]).reduce(""){$1.count>$0.count ?$1:$0}}

Try it online!