I've written a function in javascript for finding the shortest string within an array. I want the function to return empty array when the input is an empty array. How can I do that ? Here is my code:
function tinyFriend(array) {
var tiny = array[0];
for (i = 0; i < array.length; i++) {
if (array[i].length < tiny.length) {
tiny = array[i];
}
}
return tiny;
}
Aucun commentaire:
Enregistrer un commentaire