Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

37 changes: 37 additions & 0 deletions analyzeText.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.