A TypeScript project that implements custom versions of JavaScript's built-in array and object methods. This project provides educational implementations and alternative versions of native methods with identical functionality.
This project serves as:
- Educational resource for understanding how JavaScript built-in methods work internally
- Custom implementations with identical behavior to native methods
- TypeScript practice with generics, type safety, and prototype extensions
- Testing ground for exploring JavaScript array and object manipulation
CUSTOM-METHODS/
βββ src/
β βββ array/
β β βββ filter/ # Custom Array.prototype.filter implementation
β β βββ find/ # Custom Array.prototype.find implementation
β β βββ map/ # Custom Array.prototype.map implementation
β β βββ push/ # Custom Array.prototype.push implementation
β βββ object/ # Custom object methods (future implementations)
βββ public/ # Static assets
βββ node_modules/ # Dependencies
βββ main.ts # Main entry point
βββ style.css # Styling
βββ index.html # HTML entry point
βββ vite-env.d.ts # Vite environment types
βββ tsconfig.json # TypeScript configuration
βββ package.json # Project dependencies and scripts
βββ README.md # This file
- Node.js (v16 or higher)
- npm or yarn
- TypeScript knowledge
- Clone the repository:
git clone <repository-url>
cd CUSTOM-METHODS- Install dependencies:
npm install- Start the development server:
npm run devCustom implementation of Array.prototype.push().
const arr = [1, 2, 3];
const newLength = arr.customPush(4, 5); // Returns 5
console.log(arr); // [1, 2, 3, 4, 5]Custom implementation of Array.prototype.map().
const numbers = [1, 2, 3];
const doubled = numbers.customMap(x => x * 2); // [2, 4, 6]Custom implementation of Array.prototype.filter().
const numbers = [1, 2, 3, 4, 5];
const evens = numbers.customFilter(x => x % 2 === 0); // [2, 4]Custom implementation of Array.prototype.find().
const users = [{id: 1, name: 'John'}, {id: 2, name: 'Jane'}];
const user = users.customFind(u => u.id === 2); // {id: 2, name: 'Jane'}customKeys()customValues()customEntries()customHasOwnProperty()
The project includes comprehensive unit test suites using Vitest:
# Run all tests
npm test- β Unit Tests: Individual method functionality and behavior verification
- β Behavior Comparison: Direct comparison with native methods
- β Edge Cases: Empty arrays, sparse arrays, null/undefined handling
- β Type Safety: TypeScript generic constraints verification
- β Performance Benchmarks: Speed comparison with native implementations
- β Error Handling: Proper error throwing and handling
- Create a new folder in the appropriate category (
src/array/orsrc/object/) - Implement the method with proper TypeScript types
- Add comprehensive JSDoc documentation
- Create test files comparing with native behavior
- Update this README
- Use TypeScript for all implementations
- Follow JSDoc documentation standards
- Maintain identical behavior to native methods
- Include comprehensive examples
- Write tests for all edge cases
Each method follows this documentation pattern:
/**
* customMethodName - A custom implementation of the native method
*
* Brief description of what the method does and its behavior.
*
* @template T - Generic type descriptions
* @param {type} paramName - Parameter descriptions
* @returns {type} Return value description
*
* @example
* // Usage examples
* [1, 2, 3].customMethod(); // Expected output
*/This project demonstrates:
- Prototype Extensions: How to safely extend built-in prototypes
- Generic Types: Advanced TypeScript generics usage
- Algorithm Implementation: Understanding of built-in method algorithms
- Testing Strategies: Comprehensive testing approaches
- Documentation: Professional code documentation practices
- Type Safety: Full TypeScript support with proper generics
- Identical Behavior: Methods behave exactly like native implementations
- Comprehensive Testing: Extensive test suites with edge cases
- Educational Comments: Detailed inline documentation
- Modern Tooling: Vite, TypeScript, Vitest setup
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-method - Implement the method with tests and documentation
- Commit your changes:
git commit -m 'Add customMethodName' - Push to the branch:
git push origin feature/new-method - Submit a pull request
- Ensure identical behavior to native methods
- Include comprehensive tests
- Follow the established documentation format
- Add examples and edge cases
- Update the README with new methods
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This project is for educational purposes. In production code, always use the native JavaScript methods unless you have specific requirements that necessitate custom implementations.