JavaScript
JavaScript copied to clipboard
feat: Add Basic Prefix Sum Algorithm with Tests (Fixes #1783)
FIXES #1783
What does this PR do?
This PR adds an implementation of the Prefix Sum algorithm (in-place cumulative sum) in JavaScript.
Details
- Implements
prefixSuminPrefix-Sum/BasicPrefixSum.js- Validates input (must be numeric array).
- Throws
TypeErroron invalid inputs. - Modifies the array in-place and returns the same reference.
- Adds
Prefix-Sum/BasicPrefixSum.test.jswith unit tests using Vitest.- Covers integers, negatives, floats, empty input, and error handling.
Why is this needed?
Prefix sum is a fundamental algorithm widely used in competitive programming and data processing. Having an in-place implementation ensures O(1) extra space.
Checklist
- [x] Code follows repository style guidelines
- [x] Added tests with Vitest
- [x]
npm testpasses locally - [x] No console statements
Thanks for reviewing 🙏 Please let me know if changes are needed.