Your challenge: Write a function that takes a string s
, a character c
, and finds the length of the longest run of c
in s
. The length of the run will be l
.
Rules:
- If
s
is of length 0 orc
is empty,l
should be 0. - If there are no instances of
c
ins
,l
should be 0. - Standard loopholes and Standard I/O Rules apply.
- No matter where in
s
the run ofc
s is located,l
should be the same. - Any printable ASCII characters can appear in
s
andc
.
Test cases:
s,c --> l
"Hello, World!",'l' --> 2
"Foobar",'o' --> 2
"abcdef",'e' --> 1
"three spaces",' ' --> 3
"xxx xxxx xx",'x' --> 4
"xxxx xx xxx",'x' --> 4
"",'a' --> 0
"anything",'' --> 0
Winner:
As with code-golf the shortest answer in each language wins.
s
and ac
that isn't contained in a non-emptys
in your test cases? \$\endgroup\$s
/c
? \$\endgroup\$c
can be empty? In many languages, a character is just an integer with special semantics, and you can't really have an empty integer either. \$\endgroup\$