[Easy] LeetCode JS 30 - 2626. Array Reduce Transformation (手寫原生陣列 reduce 方法)

2024年3月8日

💎 加入 E+ 成長計畫 與超過 300+ 位軟體工程師一同在社群中成長,並且獲得更多的軟體工程學習資源

LeetCode 30 Days of JavaScript

本題來自 LeetCode 的 30 天 JacaScript 挑戰

2626. Array Reduce Transformation (手寫原生陣列 reduce 方法)

題目描述

本題解答

以下是本題的解答,詳細解題思路可以在 E+ 成長計畫看到

解法

var filter = function (arr, fn) {
  const returnedArr = [];
  for (let i = 0; i < arr.length; i++) {
    if (fn(arr[i], i)) {
      returnedArr.push(arr[i]);
    }
  }
  return returnedArr;
};
🧵 如果你想收到最即時的內容更新,可以在 FacebookInstagram 上追蹤我們