function shortestWordLength(text: string): number {
// Split on whitespace; filter removes empty strings
const words: string[] = text.split(/\s+/).filter(w => w.length > 0);
if (words.length === 0) {
return 0;
}
return Math.min(...words.map(w => w.length));
}
function main() {
const input = "Find the shortest word length in this string";
const result: number = shortestWordLength(input);
if (result === 0) {
console.log("No words found.");
} else {
console.log("Length of the shortest word:", result);
}
}
main();
/*
run:
"Length of the shortest word:", 2
*/