Skip to content

#205 Generate a Countdown

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

205 Generate a Countdown

Create a function that takes a number as an argument and returns an array of numbers counting down from this number to zero.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/205 Generate a Countdown.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//Create a function that takes a number as an argument and returns an array of numbers counting down from this number to zero.
function countdown(start) {
    return Array.from({ length: start + 1 }, (_, i) => start - i);
}
import { assertEquals } from '../testHelper.js';
assertEquals(countdown(3), [3, 2, 1, 0])
assertEquals(countdown(20), [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
assertEquals(countdown(1), [1, 0])
assertEquals(countdown(0), [0])

Clone this wiki locally