Skip to content

#129 Minimal1

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

129 Minimal1

Write a function that returns the string "even" if the given integer is even, and the string "odd" if it's odd.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/129 Minimal1.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.

//Write a function that returns the string "even" if the given integer is even, and the string "odd" if it's odd.
function parity(n) {
    return (n % 2) ? "odd" : "even";
}
import { assertEquals } from '../testHelper.js';
assertEquals(parity(2), 'even')
assertEquals(parity(3), 'odd')
assertEquals(parity(10), 'even')
assertEquals(parity(31), 'odd')
assertEquals(parity(666), 'even')
assertEquals(parity(777), 'odd')
assertEquals(parity(3482034), 'even')
assertEquals(parity(3482035), 'odd')

Clone this wiki locally