0
Hours
0
Minutes
0
Seconds

How to implement Array.prototype.at? JavaScript Interview Question | Problem Solving | JavaScript Polyfills

@Yomesh Gupta
17

In this question, the candidate needs to implement a function customAt that mimics the behaviour of Array.prototype.at method.

More about Array.prototype.at

The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.

Examples

const array = [5, 12, 8, 130, 44];

console.print(array.customAt(2)); // prints 8
console.print(array.customAt(-1)); // prints 44
console.print(array.customAt(100)); // prints undefined

Submission

Start the timer, complete your solution, and test it against the testcases provided by the platform. Ideally, you should finish this question within 15 mins. Share your solution with us -- https://twitter.com/devtoolstech

Loading IDE...