Skip to content

#083 Find Digit Amount

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

083 Find Digit Amount

Create a function that takes a number as an argument and returns the amount of digits it has.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/083 Find Digit Amount.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 the amount of digits it has.
function findDigitAmount(num) {
    return num.toString().length;
}
import { assertEquals } from '../testHelper.js';
assertEquals(findDigitAmount(1), 1, 'Should work with one digit')
assertEquals(findDigitAmount(67), 2, 'Should work with a two-digit number')
assertEquals(findDigitAmount(123), 3, 'Should work with a three-digit number')
assertEquals(findDigitAmount(55551), 5, 'Should work with a bit bigger number')
assertEquals(findDigitAmount(96456431), 8, 'Should work with bigger numbers')
assertEquals(findDigitAmount(0), 1, '0 should return 1, as it is a digit')

Clone this wiki locally