Skip to content

#139 Word Numbers

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

139 Word Numbers

Given an index and an array, return the value of the array with the given index.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/139 Word Numbers.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.

//Given an index and an array, return the value of the array with the given index.
function valueAt(arr, i) {
    return arr[Math.floor(i)];
}
import { assertEquals } from '../testHelper.js';
assertEquals(valueAt([1, 2, 3, 4, 5, 6], 10 / 2), 6)
assertEquals(valueAt([1, 2, 3, 4], 6.535355314 / 2), 4)
assertEquals(valueAt([1, 2], 1.0 / 2), 1)
assertEquals(valueAt([1, 2, 3, 4, 5, 6], 8.0 / 2), 5)

Clone this wiki locally