Loops and Arrays (03_removeFromArray): Add vanilla/low-level nested loop solution
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 1/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 75/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript
- 領域
- content
研究方向
從 03_removeFromArray 練習的解答檔案開始,該檔案已經包含 forEach + includes 和 filter + includes 兩種解法,以及該練習的測試套件。決定巢狀迴圈版本是要以註解掉的替代方案加入,還是作為第一個解法加入,然後檢查現有測試是否通過。完成的標準是:新解法已加入,並對 skip 旗標和內層迴圈加上說明性註解,且 03_removeFromArray 的測試仍然全部通過。
由索引模型根據 Issue 內容生成。
描述
Prerequisites
- I have thoroughly read and understand The Odin Project Contributing Guide
- I have searched the existing issues to ensure this improvement hasn't been suggested before (please have a look through our open issues list to make sure)
- The title of this issue follows the
<Location of the improvement>: <Brief description of the improvement>format, e.g.Exercises: Add exercise on XYZ - (Optional) I am interested in working on this issue and would like to be assigned to it
Improvement Description
I would like to propose adding a third, "vanilla/low-level" solution to the 03_removeFromArray exercise.
Currently, the file provides two solutions: one using .forEach() + .includes(), and a more advanced one using .filter() + .includes(). While these are great, both rely on high-level built-in methods (.includes).
Adding an imperative solution using nested loops and a flag would be highly beneficial for beginners. It demonstrates how array filtering works "under the hood" at a foundational level using only basic language constructs (for...of, conditions, and flags) without relying on any built-in lookup methods.
Acceptance Criteria
• Add the nested loops solution as an alternative commented-out approach or as the initial basic approach in the solutions file.
• Ensure the solution passes all existing test suites for 03_removeFromArray.
• Provide clear code comments explaining the algorithmic logic (e.g., the purpose of the skip flag and the inner loop breakdown).
(Optional) Additional Comments
Here is the proposed implementation for the additional solution:
const removeFromArray = function (arr, ...toDelete) {
const deletedArr = [];
for (const elementArr of arr) {
let skip = false;
// Manually checking for inclusion without using .includes()
for (const elementDelete of toDelete) {
if (elementArr === elementDelete) {
skip = true;
break; // Stop looking if a match is found
}
}
// Only push if the element was not flagged for deletion
if (!skip) deletedArr.push(elementArr);
}
return deletedArr;
};
Use code with caution.
This approach helps students strengthen their algorithmic thinking and mental models before they fully transition to abstract methods like .filter().
- 主要語言
- JavaScript
- 星號
- 1.7k
- 分支
- 48.9k
- 平均合併
- 10 小時 11 分鐘
- 30 天內合併 PR
- 6
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
相似的 Issue
-
[BUG]: Prompt compressor crashes with TypeError when a past chat has a non-string response.text可能已有人在做 @ManojDevarajulu 今天認領。 未關閉possible bug
難度 2/5 1-3 小時 新手友好度 82/100
Mintplex-Labs/anything-llm#6737 ·
維護者通常 1 天內回覆
-
check:passed feeds:add
難度 2/5 1 小時以內 新手友好度 62/100
-
bug
難度 2/5 1-3 小時 新手友好度 70/100
codex-team/editor.js#3037 ·
-
No Code Attached Yet
難度 2/5 1-3 小時 新手友好度 72/100
joomla/joomla-cms#48626 ·
維護者通常 1 天內回覆
-
complexity: trivial good first issue impact: low
難度 1/5 1 小時以內 新手友好度 78/100
ueberdosis/tiptap#8522 ·
維護者通常 1 天內回覆