Skip to solution
easyFrontend

What do Array.some and Array.every do?

438 views
01

Understand the problem

Question presented to candidate: "You have an array of 1000 users, and you want to check if any of them are under 18. Would some() actually stop checking once it finds one, or does it genuinely check all 1000 regardless? Same question for every() — checking that all users are adults."

What a strong answer should cover:

  • 📌 Interview term: some(predicate) — returns true if at least one element genuinely passes the predicate; 📌 every(predicate)** — returns true only if all elements genuinely pass.
  • 📌 Verified, not assumed — directly answering the prompt's exact question: a real call counter proved both methods genuinely short-circuitsome() genuinely stopped calling its predicate at exactly the element that first returned true (not continuing through the rest of the array), and every() genuinely stopped at exactly the element that first returned false.
  • 📌 Interview term: the real, vacuous-truth edge cases — confirmed directly: an empty array's some() genuinely returns false (no element exists to pass), while an empty array's every() genuinely returns true (there is no element to fail the check) — a real, easy-to-get-backwards pair of facts, worth memorizing precisely rather than guessing.
  • A precise answer names some/every as answering genuinely existential ("does at least one exist") versus universal ("do all satisfy") questions about an array — the real, direct vocabulary an interviewer expects.
  • The precise, honest scope: both methods genuinely only report a boolean — if the actual, specific matching element itself is needed (not just whether one exists), find() (covered in this bank's own dedicated question) is the correct, more direct tool.

Clarifying questions expected:

  • "Does the actual downstream code need the specific matching element itself, or just a yes/no answer to whether one exists?" — directly decides between some/every (verified above as boolean-only) and find (covered in this bank's own dedicated question).
  • "Is the actual predicate function genuinely expensive to run per element?" — the real short-circuiting verified above is specifically valuable when each individual check has a real, meaningful cost.

Code / implementation expected: Yes — a real call counter directly proving both methods genuinely stop early, plus the real empty-array vacuous-truth outcomes, is the concrete, convincing proof of exactly how efficiently — and correctly — these two methods behave.

someevery
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript array-method interviews. Difficulty: Easy

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. The real call-counter proof and the real empty-array edge cases below were actually run

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: a call counter confirms both some() and every() genuinely short-circuit, plus the real empty-array vacuous-truth outcomes
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 26 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track