Skip to content

#164 Recreating Property

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

164 Recreating Property

Create a function which returns the length of a string, WITHOUT using String.length property.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/164 Recreating Property.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 which returns the length of a string, WITHOUT using String.length property.
function length(s) {
    return s.split("").reduce((acc) => acc + 1, 0);
}
import { assertEquals } from '../testHelper.js';
assertEquals(length("Hello World"), 11)
assertEquals(length("Edabit"), 6)
assertEquals(length("wash your hands!"), 16)
assertEquals(length("34445"), 5)
assertEquals(length("   "), 3)
assertEquals(length(""), 0)
assertEquals(length("%%$"), 3)

Clone this wiki locally