If I have an array. Will doing this for-loop get my end result which is ‘yo’?
var list = ['words', 'three', 'yo', 'up']
function tieBreaker(array) {
var first = '';
for(var i = 0; i < list.length; i++) {
if(list[i].length <= first.length) {
first = list[i];
} else if(list[i].length === list[i].length) {
first = list[0];
}
return first;
}
}
Response to your question, I did try to execute the code and when it comes to ‘yo’ and ‘up’, the code returns back ‘up’ when in fact that ‘yo’ should be the correct response.