Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file was empty #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions polyfills/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
console.log("Polyfill of Filter");

//Always return a new array.

// Logic of for loop

// Always check for condition.

let arr = [2,4,6,8];

let arr2 = arr.filter((val)=> val < 5);

console.log(arr);
console.log(arr2);

Array.prototype.filter = null; /// for disable filter method


/////---- POlifill of filter ---///

Array.prototype.myFilter = function (callback) {
let newArray = [];

for (let i = 0; i < this.length; i++) {
if (callback(this[i], i , this)) {
newArray.push(this[i])
}
}
return newArray;
}
let arr3 = arr.myFilter((val, index, array) => val <= 6);

console.log(arr)
console.log(arr3)