-
-
Save filipecifali/defd468eeab6e079598ebc45c60c3bd5 to your computer and use it in GitHub Desktop.
t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findShortestWordAmongMixedElements(listOfWords) { | |
var data = listOfWords; | |
var result; | |
var not_a_string = data.length; | |
if (data.length == 0) { | |
return ''; | |
} | |
for(i=0;i<data.length;i++) { | |
if (typeof data[i] === 'string') { | |
if(typeof result === 'undefined') { | |
result = data[i]; | |
} | |
if(data[i].length < result.length) { | |
result = data[i]; | |
} | |
} else { | |
not_a_string--; | |
} | |
} | |
if(!not_a_string) { | |
result = ''; | |
} | |
return result; | |
} | |
findShortestWordAmongMixedElements([4,2,3,1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment