jsartisan / frontend-challenges

FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
https://frontend-challenges.com
20 stars 3 forks source link

74 - Array.prototype.filter - javascript #77

Open jsartisan opened 2 weeks ago

jsartisan commented 2 weeks ago

index.js

export function arrayFilter(array, callback) {
  const filtered = [];

  for (let i = 0; i < array.length; i++) {
    const current = array[i];

    if (callback(current, i, array)) {
      filtered.push(current);
    }
  }

  return filtered;
}