TypeScript and Best Practices: Modernizing the nth Function in JavaScript