DEV Community

loading...

Discussion on: Daily Challenge #298 - Find the Shortest Word

Collapse
celyes profile image
Ilyes Chouia

Here's the solution in PHP

Note: works only on 7.4+

function find_short(string $str): int
{
    $str = explode(' ', $str); // you can use preg_split('/\s/', $str);
    usort($str, fn($a, $b) => strlen($a) > strlen($b));
    return strlen($str[0]);
}
Enter fullscreen mode Exit fullscreen mode