Skip to content

#219 Multiply by Length

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

219 Multiply by Length

Create a function to multiply all of the values in an array by the amount of values in the given array.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/219 Multiply by Length.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 to multiply all of the values in an array by the amount of values in the given array.
function multiplyByLength(arr) {
    return arr.map(num => num * arr.length);
}
import { assertEquals } from '../testHelper.js';
assertEquals(multiplyByLength([2, 6, 4, 9]), [8, 24, 16, 36])
assertEquals(multiplyByLength([4, 1, 1]), [12, 3, 3])
assertEquals(multiplyByLength([1, 0, 3, 3, 7, 2, 1]), [7, 0, 21, 21, 49, 14, 7])
assertEquals(multiplyByLength([0]), [0])

Clone this wiki locally