Files

2.0 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56bbb991ad1ed5201cd392cc Manipula arreglos con pop() 1 https://scrimba.com/c/cRbVZAB 18236 manipulate-arrays-with-pop

--description--

Otra manera de cambiar los datos en un arreglo es con la función .pop().

.pop() se utiliza para sacar un valor del final de un arreglo. Podemos almacenar este valor sacado asignándolo a una variable. En otras palabras, .pop() elimina el último elemento de un arreglo y devuelve ese elemento.

Cualquier tipo de entrada puede ser sacada de un arreglo: números, cadenas, incluso arreglos anidados.

const threeArr = [1, 4, 6];
const oneDown = threeArr.pop();
console.log(oneDown);
console.log(threeArr);

El primer console.log mostrará el valor 6 y el segundo mostrará el valor [1, 4].

--instructions--

Utiliza la función .pop() para eliminar el último elemento de myArray, y asigna el valor sacado a un variable nuevo removedFromMyArray.

--hints--

myArray sólo debe contener [["John", 23]].

assert(
  (function (d) {
    if (d[0][0] == 'John' && d[0][1] === 23 && d[1] == undefined) {
      return true;
    } else {
      return false;
    }
  })(myArray)
);

Debes usar pop() en myArray.

assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code));

removedFromMyArray sólo debe contener ["cat", 2].

assert(
  (function (d) {
    if (d[0] == 'cat' && d[1] === 2 && d[2] == undefined) {
      return true;
    } else {
      return false;
    }
  })(removedFromMyArray)
);

--seed--

--after-user-code--

if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);

--seed-contents--

// Setup
const myArray = [["John", 23], ["cat", 2]];

// Only change code below this line

--solutions--

const myArray = [["John", 23], ["cat", 2]];
const removedFromMyArray = myArray.pop();