Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Understanding for loops

Aperta
#23 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
documentation

Direzione di ricerca

Nell'issue non è indicato alcun file del repository né alcun test. Inizia con l'esempio multiplyAll fornito e rivedi il materiale didattico circostante su JavaScript; il lavoro è completato quando il materiale spiega chiaramente cosa rappresentano i e j, perché i cicli li incrementano e come vengono attraversati gli array annidati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

question

@sophielevens asked me this question about understanding for loops. The question is from Free Code Camp.

Question
If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:

var arr = [
  [1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}

This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.
Instructions
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arrand the answer is this

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

Her questions were:

  1. Where on earth did [i] and [j] come from? Have googled it and can't find out what they mean
  2. Also, (i++) is apparently the same as (i = i + 1) why do we want to add 1 to i?
Lingua principale
HTML
Stelle
65
Fork
15
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dwyl/learn-javascript

Tutte le issue di dwyl/learn-javascript

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.