Monday, August 29, 2022

A very hard understanding of MDN snippet explained

 function myConcat(separator) {

  let result = ''; // initialize list

  // iterate through arguments

  for (let i = 1; i < arguments.length; i++) {

    result += arguments[i] + separator;

  }  return result;}


myConcat(', ', 'red', 'orange', 'blue');

Explaining that snippet the let result is '' will make when start the iteration the first element be the red and not the colon that is the first element of the arguments, but will begining with the second the red because in the iteration I called the iteration by the index equal to 1 and not the '0' that is the index of the colon, but why the colon is repeat after each element you see that our function have a parameter, that is called separator(the name isn't important could even be shitt) what is the parameter separator is now not the arguments[i] started by the 1 but started by the real first element of the array that is the colon, so the first element that is argument[0] isn't used in the iteration but is the first paremeter so is the separator that will repeat every time so is like this -->'' argument[1] argument[0] argument[2] argument[0] argument[3] argument[0];

just because the argument[0] how is the first in the line will be choiced to be the parameter separator. Rute Bezerra de Menezes Gondim 


No comments:

Post a Comment