Files
freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md
camperbot b3af21d50f chore(i18n,curriculum): update translations (#42487)
* chore(i18n,curriculum): update translations

* chore: Italian to italian

Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
2021-06-14 11:34:20 -07:00

1.8 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7dab367417b2b2512b6e Usare il metodo every per controllare che ogni elemento in un array corrisponda a un criterio 1 301312 use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria

--description--

Il metodo every funziona con gli array per controllare se ogni elemento supera un test particolare. Restituisce un valore booleano: true se tutti i valori soddisfano i criteri, false in caso contrario.

Ad esempio, il seguente codice controllerà se ogni elemento nell'array numbers è inferiore a 10:

var numbers = [1, 5, 8, 0, 10, 11];
numbers.every(function(currentValue) {
  return currentValue < 10;
});

In questo caso il metodo every restituirà false.

--instructions--

Usa il metodo every all'interno della funzione checkPositive per verificare se ogni elemento in arr è positivo. La funzione dovrebbe restituire un valore booleano.

--hints--

Il tuo codice dovrebbe utilizzare il metodo every.

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

checkPositive([1, 2, 3, -4, 5]) dovrebbe restituire false.

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

checkPositive([1, 2, 3, 4, 5]) dovrebbe restituire true.

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

checkPositive([1, -2, 3, -4, 5]) dovrebbe restituire false.

assert.isFalse(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) {
  // Only change code below this line
  return arr.every(num => num > 0);
  // Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);