Today, let's work on creating a polyfill for Array.includes() method.
NOTE: Polyfills are code snippets that provide modern functionality to older environments that don't support them.
// test cases
const array = [1, 2, 3, 4, 5];
console.log(array.myIncludes(3)); // Output: true
console.log(array.myIncludes(6)); // Output: false
Plan
To solve this problem, we'll follow these steps:
- Implement the
myIncludes
function to iterate through the array and check if the given element exists or not. - Create a new property called myIncludes on Array.prototype and assign the function.
Check the comment below to see answer.
Top comments (1)