I'm currently working on a function to find the shortest word in a given string of words.
Issue: I encountered the error below
TypeError: Cannot read property 'length' of undefined at findShort at Test.describe._ at /runner/frameworks/javascript/cw-2.js:152:11 at Promise._execute at Promise._resolveFromExecutor at new Promise at Object.describe at /home/codewarrior/index.js:24:10 at /home/codewarrior/index.js:28:5 at Object.handleError
Below is the code snippet in question
findShort("turns out random test cases are easier than writing out basic ones");
function findShort(s){
let array = s.split(" ");
let shortestWord = array[0];
for (i = 0; i < array.length; i++) {
let str = array[i + 1];
if (shortestWord.length > str.length) {
shortestWord = str.length;
}
}
return shortestWord;
}