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.
functionfind_short(str){lettimers={};constremoveTimers=()=>{Object.keys(timers).forEach(el=>clearTimeout(timers[el]));}constsetTimer=word=>{timers[word]=setTimeout(function(){alert(`The shortest word has ${word.length} characters`);removeTimers();},word.length);};str.split("").forEach(word=>setTimer(word));}
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!