I've been tasked with writing a function called "getAllWords".
Given a sentence, "getAllWords" returns an array containing every word in the sentence.
Notes: * If given an empty string, it should return an empty array.
What I've come up with is:
function getAllWords(str) {
var array = [];
for (var i = 0; i < str.length; i++) {
array.push(str[i]);
}
return array;
}
getAllWords('Radagast the Brown');
What I get is:
[ 'R','a','d','a','g','a','s','t',' ','t','h','e',' ','B','r','o','w','n']
but what I'm trying for is:
['Radagast', 'the', 'Brown']