Loading challenge...
Preparing the challenge details...
Loading challenge...
Preparing the challenge details...
Implement Array.prototype.filter from scratch. The key detail: push the original element, not the boolean result of the predicate.
filter is deceptively simple — keep elements where the callback returns truthy. The trap most candidates fall into is pushing the boolean return value instead of the original element. Get the callback signature right, support thisArg, and you have a correct implementation.
Goal: Implement myFilter correctly. Focus on pushing the original element, not the predicate result.
Continue learning with these related challenges
Implement Array.prototype.map from scratch. Master callback signatures, thisArg binding, and sparse-array hole preservation.
Implement Array.prototype.flat from scratch with a configurable depth. Default depth is 1, not Infinity.
Implement Array.prototype.reduce from scratch, including the tricky no-initial-value path and the empty-array error case.
Implement Array.prototype.map from scratch. Master callback signatures, thisArg binding, and sparse-array hole preservation.
Implement Array.prototype.flat from scratch with a configurable depth. Default depth is 1, not Infinity.
Implement Array.prototype.reduce from scratch, including the tricky no-initial-value path and the empty-array error case.