freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../functional-programming/use-the-some-method-to-chec...

2.3 KiB

id title challengeType videoUrl localeTitle
587d7dab367417b2b2512b6f Use the some Method to Check that Any Elements in an Array Meet a Criteria 1 Use el método para verificar que cualquier elemento de una matriz cumpla con los criterios

Description

El método de some funciona con matrices para verificar si algún elemento pasa una prueba en particular. Devuelve un valor booleano: true si alguno de los valores cumple los criterios, false si no. Por ejemplo, el siguiente código verificará si algún elemento de la matriz de numbers es menor que 10:
números var = [10, 50, 8, 220, 110, 11];
numbers.some (function (currentValue) {
return currentValue <10;
});
// Devuelve true

Instructions

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

Tests

tests:
  - text: Su código debe utilizar <code>some</code> método.
    testString: 'assert(code.match(/\.some/g), "Your code should use the <code>some</code> method.");'
  - text: '<code>checkPositive([1, 2, 3, -4, 5])</code> debe devolver <code>true</code> .'
    testString: 'assert(checkPositive([1, 2, 3, -4, 5]), "<code>checkPositive([1, 2, 3, -4, 5])</code> should return <code>true</code>.");'
  - text: '<code>checkPositive([1, 2, 3, 4, 5])</code> debe devolver <code>true</code> .'
    testString: 'assert(checkPositive([1, 2, 3, 4, 5]), "<code>checkPositive([1, 2, 3, 4, 5])</code> should return <code>true</code>.");'
  - text: '<code>checkPositive([-1, -2, -3, -4, -5])</code> debe devolver <code>false</code> .'
    testString: 'assert(!checkPositive([-1, -2, -3, -4, -5]), "<code>checkPositive([-1, -2, -3, -4, -5])</code> should return <code>false</code>.");'

Challenge Seed

function checkPositive(arr) {
  // Add your code below this line


  // Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);

Solution

// solution required