every
funciona com arrays para verificar se cada elemento passa por um teste específico. Retorna um valor booleano - true
se todos os valores atendem aos critérios, false
se não. Por exemplo, o código a seguir verificaria se cada elemento na matriz de numbers
é menor que 10: números var = [1, 5, 8, 0, 10, 11];
numbers.every (function (currentValue) {
return currentValue <10;
});
// Retorna falso
every
dentro da função checkPositive
para verificar se todos os elementos em arr
são positivos. A função deve retornar um valor booleano. every
.
testString: 'assert(code.match(/\.every/g), "Your code should use the every
method.");'
- text: 'checkPositive([1, 2, 3, -4, 5])
deve retornar false
.'
testString: 'assert(!checkPositive([1, 2, 3, -4, 5]), "checkPositive([1, 2, 3, -4, 5])
should return false
.");'
- text: 'checkPositive([1, 2, 3, 4, 5])
deve retornar true
.'
testString: 'assert(checkPositive([1, 2, 3, 4, 5]), "checkPositive([1, 2, 3, 4, 5])
should return true
.");'
- text: 'checkPositive([1, -2, 3, -4, 5])
deve retornar false
.'
testString: 'assert(!checkPositive([1, -2, 3, -4, 5]), "checkPositive([1, -2, 3, -4, 5])
should return false
.");'
```