I'm facing an issue with a program that is supposed to piece together all the letters, but it's not functioning correctly. I've tried using the debugger, but it doesn't display any errors. Here's the code snippet:
var phrase = [ 'h', 'e', 'l', 'l', 'o',' ', 'w', 'o', 'r', 'l', 'd' ];
let sentence: string[] = createSentence(phrase);
sentence.forEach(letter => {
console.log(letter);
});
function createSentence(letters: string[]): string[]
{
var add = "";
var result: string[] = [];
phrase.forEach(unionL => {
if (unionL != ' ') {
add += unionL;
} else {
result.push(add);
add = "";
}
});
return result;
}