Skip to content

#096 Arguments Count

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

096 Arguments Count

Create a function that returns the number of arguments it was called with.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/096 Arguments Count.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 returns the number of arguments it was called with.
function numArgs() {
    return arguments.length;
}
import { assertEquals } from '../testHelper.js';
assertEquals(numArgs(), 0)
assertEquals(numArgs('foo'), 1)
assertEquals(numArgs('foo', 'bar'), 2)
assertEquals(numArgs(null, null), 2)
assertEquals(numArgs('foo', 'bar', 5, null), 4)
assertEquals(numArgs(false), 1)
assertEquals(numArgs('foo', {}), 2)
assertEquals(numArgs('foo', 'bar', {}), 3)
assertEquals(numArgs([], [], {}), 3)
assertEquals(numArgs('foo', 'bar', true, null, 0), 5)
assertEquals(numArgs('a', 'b', 'c'), 3)
assertEquals(numArgs(10, 20, 30, 40, 50), 5)
assertEquals(numArgs('x', 'y'), 2)
assertEquals(numArgs(), 0)

Clone this wiki locally