In this question, the candidate needs to implement a function
customFindIndex that mimics the behaviour of
findIndex() method returns the index of the first element in an array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.
const array = [1,2,3,12,13,15]; const greaterThanTen = (element) => element > 10; console.print(array.findIndex(greaterThanTen)); // expected output: 3
customFindIndex takes two parameters
Function to execute on each value in the array. The function is called with the following arguments:
- The current element in the array.
- The index (position) of the current element in the array.
- The array that
customFindwas called on.
The callback must return a truthy value to indicate a matching element has been found.
Object to use as
this inside callbackFn.
Start the timer, complete your solution, and test it against the test cases provided by the platform. Ideally, you should finish this question within 15 mins. Share your solution with us -- https://twitter.com/devtoolstech