function countWords(str) { let counts = {}; let words = str.split(' '); for (let word of words) { if (word.length > 0) { if (!(word in counts)) { counts[word] = 0; } counts[word] += 1; } } return counts; }