Array Every and Some in JavaScript
Level 3142 keystrokes
every() checks if all elements pass a test, some() checks if at least one does.
JavaScript code
// Create an array of even numbers1const nums = [2, 4, 6, 8];// every() returns true if ALL elements satisfy the condition// All numbers are even, so returns true2console.log(nums.every(n => n % 2 === 0));// some() returns true if AT LEAST ONE element satisfies the condition// 6 and 8 are > 5, so returns true3console.log(nums.some(n => n > 5));// No number is > 10, so returns false4console.log(nums.some(n => n > 10));Output
true true false
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
=× 7.× 6(× 6)× 6>× 5;× 4,× 3[× 1]× 1%× 1