Problem, as an interviewer would state it:
"Implement Array.prototype.myIncludes from scratch — and explain, with real proof, exactly why it exists as a SEPARATE method from indexOf, rather than callers just checking indexOf(x) !== -1."
Examples:
[1, NaN, 3].includes(NaN); // true
[1, NaN, 3].indexOf(NaN); // -1 -- genuinely, permanently cannot find it
Clarifying questions expected:
- What comparison algorithm does includes() genuinely use internally — is it the same strict equality (===) that indexOf uses?
- Does includes() need to support a negative fromIndex, counting back from the end?
- Does +0 and -0 need to be treated as equal, matching real native includes()'s documented behavior?
Code / implementation expected: Yes — real, direct proof that includes() finds a real NaN while indexOf genuinely cannot, PLUS proof of negative fromIndex and +0/-0 handling, both matching real native includes exactly.