We made a video new video on Shadcn UI. Check it out!
JS Polyfill: Array.at() Method

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.

affiliate

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

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.

affiliate

Last updated on

On this page