Given a string of words, return the length of the shortest word in the string.
Examples
find_short("bitcoin take over the world maybe who knows perhaps"), 3)
find_short("turns out random test cases are easier than writing out basic ones"), 3)
Tests
find_short("let us talk about javascript")
find_short("i want to travel the world writing code one day")
find_short("Lets all go on holiday somewhere very cold")
Good luck!
This challenge comes from A.Partridge on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (8)
Here is an answer in python
Here is a silly answer in the same spirit as the sorting by using time outs. The idea is, instead of trying to calculate/compare sizes, setting a timeout for each word with a delay equal to its length. The timeout callback will show the result and cancel the other timeouts.
Here is the code (demo with the code running on Codepen):
nice, you are so creative!
Here is an answer in node (first time I write something in node :) ) :
Here's the solution in PHP
Note: works only on 7.4+
Here is the simple solution with PHP:
Elm
My js solution: