2.3 KiB
2.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dab367417b2b2512b6e | Use the every Method to Check that Every Element in an Array Meets a Criteria | 1 | Use cada método para verificar que cada elemento de una matriz cumple con los criterios |
Description
every
método funciona con matrices para verificar si cada elemento pasa una prueba en particular. Devuelve un valor booleano: true
si todos los valores cumplen los criterios, false
si no. Por ejemplo, el siguiente código verificará si cada elemento de la matriz de numbers
es menor que 10: números var = [1, 5, 8, 0, 10, 11];
numbers.every (function (currentValue) {
return currentValue <10;
});
// Devuelve falso
Instructions
every
método dentro de la función checkPositive
para verificar si cada elemento en arr
es positivo. La función debe devolver un valor booleano. Tests
tests:
- text: Su código debe utilizar <code>every</code> métodos.
testString: 'assert(code.match(/\.every/g), "Your code should use the <code>every</code> method.");'
- 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>.");'
- 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