Overview
JS Polyfill: Array.at() Method
GreatFrontEnd has better questions!
We don't create questions because GreatFrontEnd already has the best possible library of questions and we recommend the same to our community.
Questions are deprecated!
These are the interview practice questions from the legacy versions of Frontend Hire. Only the ones with a video solution are available. Moving forward, we won't be releasing more questions as this is not our strongest content.
Fork on Stackblitz
Click on the "Fork" button on the bottom-left corner of the editor to fork the code on Stackblitz and to solve this question in a separate browser tab.
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
undefined
for 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
undefined
for an index that is out of the array's bounds.
You can also do a TDD approach to this problem if you prefer.
Resources to Refer
- ECMAScript Language Specification: Array.prototype.at
- MDN Web Docs: Array.at()
- What is a Polyfill?
- JavaScript Info: Polyfills and transpilers
- Using Web Platform Tests to Write and Test Polyfills
Promote your product or service here
Get in front of thousands of frontend developers and tech enthusiasts with our advertising slots.
GreatFrontEnd has better questions!
We don't create questions because GreatFrontEnd already has the best possible library of questions and we recommend the same to our community.
Last updated on