diff --git a/README.md b/README.md new file mode 100644 index 0000000..3415e9a --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +This is an Introduction on How to use Github, VSCode and install some usefull extenstion depending on the Track + +Check the Files to install the installations and learn the git commands + + + + + +WD First Assignment +https://github.com/TechLabs-Dusseldorf/Assignments1 + + +signed by Geeti + diff --git a/analyzeText.js b/analyzeText.js new file mode 100644 index 0000000..db5fa4d --- /dev/null +++ b/analyzeText.js @@ -0,0 +1,37 @@ +function analyzeText(paragraph, topN = 5) { + if (!paragraph || typeof paragraph !== 'string') return { totalWords: 0, uniqueWords: 0, averageWordLength: 0, topWords: [] }; + + // 1. Normalize text and remove punctuation + const cleaned = paragraph.toLowerCase().replace(/[^\w\s]/g, ' '); + + // 2. Split into words + const words = cleaned.trim().split(/\s+/).filter(Boolean); + + const totalWords = words.length; + let totalLength = 0; + const freq = {}; + + // 3. Count words & total length + for (const w of words) { + totalLength += w.length; + freq[w] = (freq[w] || 0) + 1; + } + + const uniqueWords = Object.keys(freq).length; + const averageWordLength = totalWords ? Number((totalLength / totalWords).toFixed(2)) : 0; + + // 4. Get top N words + const topWords = Object.entries(freq) + .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) + .slice(0, topN) + .map(([word, count]) => ({ word, count })); + + return { + totalWords, + uniqueWords, + averageWordLength, + topWords + }; +} + +module.exports = analyzeText; diff --git a/index.js b/index.js new file mode 100644 index 0000000..87d1e58 --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +const analyzeText = require('./analyzeText'); + +const paragraph = `The demand for individuals with tech skills is increasing. The good news is that you do not have to study IT to learn coding! We help you enter the Tech World – independent of your prior knowledge. Our Digital Shaper Program combines online learning, project work and community events to make learning as fun and easy as possible. As we believe that education should be free for everyone we are pleased to educate Techies in our four courses: Web Development, Data Science, Artificial Intelligence and UX-Design. We believe that these tracks are perfect to get started and enter the tech world. Sign up for our program beginning of each semester.`; + +console.log(analyzeText(paragraph));