Skip to content

Instantly share code, notes, and snippets.

@filipecifali
Last active May 27, 2018 18:54
Show Gist options
  • Save filipecifali/defd468eeab6e079598ebc45c60c3bd5 to your computer and use it in GitHub Desktop.
Save filipecifali/defd468eeab6e079598ebc45c60c3bd5 to your computer and use it in GitHub Desktop.
t
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