Question Bank

JavaScript Count Backward by Evens: Two Approaches Quiz

Difficulty: Medium

Two seeded approaches to enumerate even numbers descending from n (filter-on-step-1 vs step-2 loop), plus two companions on Array.from and an odd-start edge case.

Question Bank
/

JavaScript Count Backward by Evens: Two Approaches Quiz

JavaScript Count Backward by Evens: Two Approaches Quiz

Two seeded approaches to enumerate even numbers descending from n (filter-on-step-1 vs step-2 loop), plus two companions on Array.from and an odd-start edge case.

Question Bank
Medium
JavaScript
4 questions
quiz
loops
arrays
fundamentals

1,121 views

36

Implement countBackward(n) that returns an array of even numbers descending from n down to (but excluding) 0. Solve it with a step-1 loop and an internal filter.

Examples

Example 1:

Input: 12
Output: [12, 10, 8, 6, 4, 2]
Explanation: Every even number from 12 down to 2 inclusive.

Example 2:

Input: 7
Output: [6, 4, 2]
Explanation: 7 is odd, so the loop skips it and starts collecting at 6.