Solución
solution.tsTypeScript
export function longestCommonPrefix(words: string[]): string {
// Escribe tu solución aquí
let results = {}
let prexLarge = ''
for (let w of words) {
let charT = 1
while (charT <= w.length) {
let sliced = w.slice(0, charT)
results[sliced] = results[sliced]? results[sliced] + 1: 1
if (!results[prexLarge] || results[sliced] >= results[prexLarge]) {
prexLarge = sliced
}
charT++
}
}
if (words.length == 1) {
return prexLarge
}
return results[prexLarge] > 1? prexLarge : '';
}0respuestas