Files
freeCodeCamp/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md
2021-10-27 21:47:35 +05:30

1.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7dab367417b2b2512b6f Usa el método "some" para comprobar si algún elemento en un arreglo cumple un criterio 1 301314 use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria

--description--

El método some funciona con arreglos para comprobar si algún elemento pasa una prueba en particular. Devuelve un valor booleano true si alguno de los valores cumple el criterio, false si no.

Por ejemplo, el siguiente código comprobará si algún elemento en el arreglo numbers es menor que 10:

const numbers = [10, 50, 8, 220, 110, 11];

numbers.some(function(currentValue) {
  return currentValue < 10;
});

El método some devolverá true.

--instructions--

Utiliza el método some dentro de la función checkPositive para comprobar si algún elemento en arr es positivo. La función debe devolver un valor booleano.

--hints--

Tu código debe usar el método some.

assert(code.match(/\.some/g));

checkPositive([1, 2, 3, -4, 5]) debe devolver true.

assert(checkPositive([1, 2, 3, -4, 5]));

checkPositive([1, 2, 3, 4, 5]) debe devolver true.

assert(checkPositive([1, 2, 3, 4, 5]));

checkPositive([-1, -2, -3, -4, -5]) debe devolver false.

assert(!checkPositive([-1, -2, -3, -4, -5]));

--seed--

--seed-contents--

function checkPositive(arr) {
  // Only change code below this line


  // Only change code above this line
}

checkPositive([1, 2, 3, -4, 5]);

--solutions--

function checkPositive(arr) {
  return arr.some(elem => elem > 0);
}