Skip to content

#131 Minimal3

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

131 Minimal3

Write a function that returns the strings: "both" if both given booleans a and b are true. "first" if only a is true. "second" if only b is true . "neither" if both a and b are false.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/131 Minimal3.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 strings:
"both" if both given booleans a and b are true.
"first" if only a is true.
"second" if only b is true .
"neither" if both a and b are false.*/
function areTrue(a, b) {
    if (a && b) return "both";
    if (a) return "first";
    if (b) return "second";
    return "neither";
}
import { assertEquals } from '../testHelper.js';
assertEquals(areTrue(true, true), "both")
assertEquals(areTrue(true, false), "first")
assertEquals(areTrue(false, true), "second")
assertEquals(areTrue(false, false), "neither")

Clone this wiki locally