feat: add array manipulation utilities for chunking, flattening, deduplication and rotation #236
+1,130
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add 4 Practical Array Algorithm Examples
📋 Summary
This PR adds four new comprehensive array algorithm examples to the
03-arraychapter, covering common interview questions and real-world use cases. Each example includes both JavaScript and TypeScript implementations with multiple approaches, performance comparisons, and practical examples.🎯 Motivation
These array algorithms are frequently encountered in:
The examples fill gaps in the existing array chapter by providing practical, production-ready implementations with detailed explanations.
✨ What's New
1. Array Chunking (
11-array-chunking.js/ts)Split arrays into smaller chunks of a specified size.
Features:
Use Cases:
Example:
2. Flatten Nested Arrays (
12-flatten-arrays.js/ts)Convert multi-dimensional arrays into single-dimensional arrays.
Features:
flat()method with depth controlUse Cases:
Example:
3. Remove Duplicates (
13-remove-duplicates.js/ts)Eliminate duplicate values from arrays with multiple strategies.
Features:
Use Cases:
Example:
4. Array Rotation (
14-array-rotation.js/ts)Rotate array elements left or right by k positions.
Features:
Use Cases:
Example:
📁 Files Added
Total: 8 new files, ~1,200 lines of well-documented code
🎓 Educational Value
Each example includes:
🧪 Testing
All examples have been manually tested and verified:
Test commands:
📊 Performance Highlights
Based on testing with large arrays (10,000 elements):
Remove Duplicates:
Flatten Arrays:
flat()is optimized and recommendedArray Rotation:
🔄 Consistency with Existing Code
These examples follow the established patterns in the repository:
##-description.js/ts)🚀 How to Use
Run any example individually:
Or navigate to the directory:
cd src/03-array node 11-array-chunking.js💡 Future Enhancements
Potential follow-up additions:
📚 References
These implementations are based on:
✅ Checklist
🤝 Contributing
These examples are ready for:
📝 Notes for Reviewers
Ready to merge! 🎉
These additions significantly enhance the array chapter with practical, interview-ready algorithms that learners will find immediately useful.