feat(norms): add TypeScript support and update documentation#312
feat(norms): add TypeScript support and update documentation#312aditisingh02 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughUpdated the Norms & Distances lesson metadata to include TypeScript and added a new TypeScript lesson module with distance, similarity, statistical, and distribution metrics plus console demos and entrypoint wiring. ChangesNorms & Distances TypeScript lesson
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
phases/01-math-foundations/14-norms-and-distances/code/distances.ts (1)
4-4: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPrefer canonical sources over Wikipedia in citations.
The header cites Wikipedia for norms and Levenshtein distance. Per the repo guideline, code comments should cite RFCs, official specs, or academic papers as the canonical source (e.g., Levenshtein, V. I. (1966), Soviet Physics Doklady) rather than Wikipedia.
As per coding guidelines: "Cite RFCs, official specs, and academic papers when they are the canonical source."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@phases/01-math-foundations/14-norms-and-distances/code/distances.ts` at line 4, Replace the Wikipedia references in the top-of-file citation comment in distances.ts with canonical sources: use an academic paper or other primary source for the norm definition and Levenshtein distance instead of Wikipedia. Update the comment near the file header so it points to the authoritative references for the concepts mentioned, keeping the rest of the file unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@phases/01-math-foundations/14-norms-and-distances/docs/en.md`:
- Line 434: The docs in the norms-and-distances section reference `distances.ts`
directly, which conflicts with the `main.*` naming convention. Update the run
command in the same place as the `code/distances.ts` mention so it uses
`main.ts` if the file is renamed, and make sure both the filename and command
stay aligned together.
---
Nitpick comments:
In `@phases/01-math-foundations/14-norms-and-distances/code/distances.ts`:
- Line 4: Replace the Wikipedia references in the top-of-file citation comment
in distances.ts with canonical sources: use an academic paper or other primary
source for the norm definition and Levenshtein distance instead of Wikipedia.
Update the comment near the file header so it points to the authoritative
references for the concepts mentioned, keeping the rest of the file unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fa4d106b-15fb-4a86-8c02-1a251432b013
📒 Files selected for processing (4)
README.mdphases/01-math-foundations/14-norms-and-distances/code/distances.tsphases/01-math-foundations/14-norms-and-distances/docs/en.mdsite/data.js
| ### Step 1: All norm and distance functions | ||
|
|
||
| See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. | ||
| See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. `code/distances.ts` is a from-scratch TypeScript port of the same functions and demos — run it with `npx tsx distances.ts`. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Run command references distances.ts directly — inconsistent with the main.* convention.
The instruction npx tsx distances.ts implies readers run the file directly by name. If the file is renamed to main.ts (to satisfy the frontmatter guideline above), this command should become npx tsx main.ts. Both changes should land together to stay consistent.
✏️ Proposed update (conditional on renaming the file)
-See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. `code/distances.ts` is a from-scratch TypeScript port of the same functions and demos — run it with `npx tsx distances.ts`.
+See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. `code/main.ts` is a from-scratch TypeScript port of the same functions and demos — run it with `npx tsx main.ts`.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. `code/distances.ts` is a from-scratch TypeScript port of the same functions and demos — run it with `npx tsx distances.ts`. | |
| See `code/distances.py` for the complete implementation. Every function is built from scratch using only basic Python math. `code/main.ts` is a from-scratch TypeScript port of the same functions and demos — run it with `npx tsx main.ts`. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@phases/01-math-foundations/14-norms-and-distances/docs/en.md` at line 434,
The docs in the norms-and-distances section reference `distances.ts` directly,
which conflicts with the `main.*` naming convention. Update the run command in
the same place as the `code/distances.ts` mention so it uses `main.ts` if the
file is renamed, and make sure both the filename and command stay aligned
together.
Source: Coding guidelines
What this PR does
Adds a from-scratch TypeScript port of the Phase 1 · Lesson 14 (Norms & Distances) code, mirroring every function and demo in the existing Python implementation.
Kind of change
Checklist
LESSON_TEMPLATE.mdstructure[Name](phases/...)), not bare textdocs/en.mdclaimsPhase / lesson
Phase 1 · 14-norms-and-distances
Notes for reviewer
phases/01-math-foundations/14-norms-and-distances/code/distances.ts— a from-scratch port (no framework, nopackage.json), beside the existingdistances.py. Follows the repo's established port pattern (cf.00-setup-and-tooling/01-dev-environment/, whereverify.py/verify.ts/main.rscoexist). Run withnpx tsx distances.ts.random(Mersenne Twister), which can't be reproduced exactly in JS. I added a small seeded PRNG (mulberry32 + Box–Muller) so the randomized demos are deterministic. Fixed-input demos (norms, distances, cosine, KL, Wasserstein) match the Python output exactly; the randomized demos produce different numbers but preserve every narrative conclusion the docs claim (e.g. Mahalanobis flagging the off-axis point that L2 misses, L1 driving weights to exact zero).npx tsx distances.ts→ exit 0;tsc --strict --types node→ exit 0.docs/en.md**Language:**line + a note on the TS port;README.mdLangcolumn;site/data.jsrebuilt vianode site/build.js(diff is only the timestamp + the changedlangfield).Resolves Issue #311