Loops and Arrays (03_removeFromArray): Add vanilla/low-level nested loop solution
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- content
Direzione di ricerca
Inizia dal file delle soluzioni dell'esercizio 03_removeFromArray, che contiene già le soluzioni con forEach + includes e filter + includes, e dalla suite di test di quell'esercizio. Decidi se la versione con cicli annidati va inserita come alternativa commentata o come prima soluzione, quindi verifica che i test esistenti passino. È completato quando la nuova soluzione è presente con commenti esplicativi sul flag di skip e sul ciclo interno, e i test di 03_removeFromArray continuano a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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().
- Lingua principale
- JavaScript
- Stelle
- 1.7k
- Fork
- 48.9k
- Merge medio
- 10h 11m
- PR unite (30g)
- 6
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Issue simili
-
Four problem loader browser tests fail on WindowsForse già presa @Patriciaath999 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
juice-shop/juice-shop#3686 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
TheOdinProject/curriculum#31465 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
TurboDocx/html-to-docx#254 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno