Solución
solution.tsTypeScript
function wordBreak(words: string[], sentence: string): string[] | null {
let currentWord = '';
const output:string[] = []
let wordFound = false
for(let i = 0; i < sentence.length; i ++) {
currentWord += sentence[i];
wordFound = false;
const howMany = words.filter(word => word.startsWith(currentWord) ).length;
if ( howMany > 1) continue;
if ( !words.some( (word) => word === currentWord)) continue;
output.push(currentWord);
currentWord = '';
wordFound = true;
}
if (!wordFound) return null;
return output.length === 0 ? null : output;
}
// No modificar: necesario para evaluar el resultado.
export { wordBreak };0respuestas