Repository navigation
#123 Simple Array Manipulation
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Help fix all the bugs in the function incrementItems!
It is intended to add 1 to every element in the array!
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/123 Simple Array Manipulation.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.
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.
//Help fix all the bugs in the function incrementItems!
//It is intended to add 1 to every element in the array!
function incrementItems(arr) {
for (let i = 0; i < arr.length; i++)
arr[i] = arr[i] + 1
return arr
}
import { assertEquals } from '../testHelper.js';
assertEquals(incrementItems([0, 1, 2, 3]), [1, 2, 3, 4])
assertEquals(incrementItems([2, 4, 6, 8]), [3, 5, 7, 9])
assertEquals(incrementItems([-1, -2, -3, -4]), [0, -1, -2, -3])