Skip to content

#255 Arithmetic Progression

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

255 Arithmetic Progression

Return the first n elements of the sequence with the given common difference diff.

The final result should be a string of numbers, separated by comma and space.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/255 Arithmetic Progression.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.

//Return the first n elements of the sequence with the given common difference diff.
//The final result should be a string of numbers, separated by comma and space.
function arithmeticProgression(start, diff, n) {
    return Array.from({ length: n }, (_, i) => start + diff * i).join(", ")
}
import { assertEquals } from '../testHelper.js';
assertEquals(arithmeticProgression(1, 2, 5), "1, 3, 5, 7, 9")
assertEquals(arithmeticProgression(1, 0, 5), "1, 1, 1, 1, 1")
assertEquals(arithmeticProgression(1, -3, 10), "1, -2, -5, -8, -11, -14, -17, -20, -23, -26")
assertEquals(arithmeticProgression(100, -10, 10), "100, 90, 80, 70, 60, 50, 40, 30, 20, 10")

Clone this wiki locally