Question
Back to the future! - Array edition.
Polyfills are a way to add functionality to the JavaScript language by implementing methods that are not natively supported. This is useful for older browsers that do not support newer features of the language. Also, they are interview questions that are commonly asked in JavaScript interviews. In this exercise, you will implement a polyfill for the Array.at() method.
Objectives
- Implement a polyfill for the Array.at() method.
- The method should work for both positive and negative integers.
- It should return
undefinedfor out-of-bound indices.
Tests
Consider writing tests for the following scenarios:
- The method returns the correct item for a positive index.
- The method returns the correct item for a negative index.
- The method returns
undefinedfor an index that is out of the array's bounds.
You can also do a TDD approach to this problem if you prefer.