Repository navigation
#030 Buggy Code5
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Mubashir created an infinite loop!
Help him by fixing the code in the code tab to pass this challenge.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/030 Buggy Code5.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.
//Mubashir created an infinite loop!
//Help him by fixing the code in the code tab to pass this challenge.
function printArray(number) {
const newArray = [];
for (let i = 1; i <= number; i++) {
newArray.push(i);
}
return newArray;
}
import * as Test from '../testHelper.js';
Test.assertEquals(printArray(1), [1])
Test.assertEquals(printArray(2), [1, 2])
Test.assertEquals(printArray(3), [1, 2, 3])
Test.assertEquals(printArray(4), [1, 2, 3, 4])
Test.assertEquals(printArray(5), [1, 2, 3, 4, 5])
Test.assertEquals(printArray(6), [1, 2, 3, 4, 5, 6])
Test.assertEquals(printArray(7), [1, 2, 3, 4, 5, 6, 7])
Test.assertEquals(printArray(8), [1, 2, 3, 4, 5, 6, 7, 8])
Test.assertEquals(printArray(9), [1, 2, 3, 4, 5, 6, 7, 8, 9])
Test.assertEquals(printArray(10), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])