Problem, as an interviewer would state it:
"Implement Array.prototype.myFindLast and myFindLastIndex — like find/findIndex, but searching from the END of the array toward the START, returning the LAST matching element."
Examples:
[5, 12, 8, 130, 44].myFindLast(n => n > 10); // 44 -- the LAST element greater than 10
Clarifying questions expected:
- What is the real, correct "no match found" return value for each — matching find()'s own undefined, and findIndex()'s own -1, respectively?
- Does this genuinely need to search from the end for efficiency, or would reversing the array first and using find() be equally correct?
- Should real sparse-array holes be handled the same way as find()'s own real, documented behavior (which does NOT skip holes, unlike map/filter)?
Code / implementation expected: Yes — real, direct proof against the ACTUAL native findLast/findLastIndex, confirming identical output including the correct "no match" conventions.