Skip to content

feat: port alternating digit sum solution to javascript - #246

Merged
Huerte merged 3 commits into
Huerte:mainfrom
Aaqibhafeezkhan:port-practice101-javascript
Nov 12, 2026
Merged

Huerte merged 3 commits into
Huerte:mainfrom
Aaqibhafeezkhan:port-practice101-javascript

Conversation

@Aaqibhafeezkhan

Copy link
Copy Markdown
Contributor

Summary

  • Ported Python solution (practice101.py) to JavaScript
  • Implements the alternating digit sum algorithm
  • Maintains the same logic and time complexity O(d)

Details

  • Language: JavaScript
  • Problem: Calculate Alternating Digit Sum (LeetCode)
  • File: solutions/javascript/practice2.js
  • Ported from: python/practice101.py

This solution reads digits from left to right, adding the first digit, subtracting the next, and continuing to alternate. For example: 521 becomes 5 - 2 + 1 = 4.

Test plan

  • Verified logic matches original Python solution
  • Added "Ported from" comment as per guidelines
  • Kept header comment with problem source and notes
  • Tested with sample input (521 → 4)

Closes #219

Aaqibhafeezkhan and others added 2 commits November 12, 2026 07:12
Link to original Codewars problem: Multi-tap Keypad Text Entry on an Old Mobile Phone

This helps learners find the original problem statement and understand the T9-style multi-tap keypad input mechanism.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Port of python/practice101.py to JavaScript.

Solves the problem of calculating alternating digit sums by reading digits left to right, alternating between addition and subtraction.

Closes Huerte#219
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aaqibhafeezkhan

  • ✅ Selected practice101.py - a simple, well-documented alternating digit sum problem
  • ✅ Ported logic to JavaScript with equivalent functionality
  • ✅ Added "Ported from: python/practice101.py" header comment per guidelines
  • ✅ Maintained the same time complexity O(d)
  • ✅ Preserved problem description and source link

This is a straightforward port that helps beginners learn JavaScript by studying a solved algorithm they can already read in Python!

@Huerte
Huerte merged commit 7a9a7d1 into Huerte:main Nov 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Translate an existing Python solution into another language (15 min)

2 participants