Build a comprehensive text analysis tool that counts words, characters, sentences, and provides readability metrics
Create a text analysis tool that provides real-time statistics as users type. Display word count, character count (with and without spaces), sentence count, paragraph count, and reading time estimates.
function analyzeText(text) {
const words = text.trim().split(/\s+/).filter(word => word.length > 0);
const characters = text.length;
const charactersNoSpaces = text.replace(/\s/g, '').length;
const sentences = text.split(/[.!?]+/).filter(s => s.trim().length > 0);
const paragraphs = text.split(/\n\s*\n/).filter(p => p.trim().length > 0);
return {
wordCount: words.length,
characterCount: characters,
characterCountNoSpaces: charactersNoSpaces,
sentenceCount: sentences.length,
paragraphCount: paragraphs.length,
readingTime: Math.ceil(words.length / 200)
};
}