samedi 28 mars 2020

Please tell me the mechanism of this code [closed]

function multiply(arr, n) {
    if (n <= 0) {
      return 1;
    } else {
      return multiply(arr, n - 1) * arr[n - 1];
    }
  }
var element = multiply([1,5,5,5,5,], 3);
console.log(element); //output: 1*5*5 = 25;

How this multiplication occurs? Please tell me the details. Thank you.

Aucun commentaire:

Enregistrer un commentaire