Perl solution. The special array @_ contains the arguments of a subroutine, but in scalar context it returns the number of them.
#!/usr/bin/perlusewarnings;usestrict;usefeatureqw{ say };sub likes{my$count=@_-2;sprintf((('no one','%s','%s and %s','%s, %s, and %s',)[scalar@_]||"%s, %s, and $count others").' like%s this',@_[0..(@_>3?1:$#_)],'s'x(@_<2))}useTest::Moretests=>5;islikes(),'no one likes this';islikes('Peter'),'Peter likes this';islikes('Jacob','Alex'),'Jacob and Alex like this';islikes('Max','John','Mark'),'Max, John, and Mark like this';islikes('Alex','Jacob','Mark','Max'),'Alex, Jacob, and 2 others like this';
0xford comma included.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perl solution. The special array
@_
contains the arguments of a subroutine, but in scalar context it returns the number of them.0xford comma included.