Repository navigation
#032 Buggy Code7
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Mubashir wants to swap two given numbers!
It is not returning the right values. Can you help him fix it?
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/032 Buggy Code7.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 wants to swap two given numbers!
//It is not returning the right values. Can you help him fix it?
function swap(a, b) {
[a, b] = [b, a];
return [a, b]
}
import * as Test from '../testHelper.js';
Test.assertEquals(swap(100, 200), [200, 100])
Test.assertEquals(swap(44, 33), [33, 44])
Test.assertEquals(swap(21, 12), [12, 21])
Test.assertEquals(swap(10, 20), [20, 10])