🔘 Array.prototype.some() Polyfill
Category: js / polyfills
Difficulty: medium
The some() method tests whether at least one element in the array passes the test implemented by the provided function. ✅ Implementation [code example] How This Works Checks if callback is a function If not, it throws a TypeError (same behavior as Array.prototype.some). Iterates through the array Calls callback for each element with (element, index, array). Uses .call(thisArg, ...) to bind the optional thisArg. Returns early if a match is found If callback returns true, customSome immediately returns true. Returns false if no match is found If no element passes the test, customSome returns false after the loop. Edge Cases Handled ✔ Empty array always returns false ✔ Works with thisArg binding ✔ Stops checking as soon as one match is found (Optimized) ✔ Throws an error if callback is not a function This version is simple, efficient, and follows the behavior of Array.prototype.some exactly. <!-- quiz-start --> Q1: What does [].customSome(x => x > 0) return? [ ] true [x] false [ ] undefined [ ] Throws an error Q2: When does some() return true? [ ] When all elements pass the test [x] When at least one element passes the test [ ] When no elements pass the test [ ] When the array is empty...