Repository navigation
#279 Object Empty
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Write a function that returns true if an object is empty, and false otherwise.
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/279 Object Empty.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.
//Write a function that returns true if an object is empty, and false otherwise.
function isEmpty(obj) {
return Object.keys(obj).length === 0;
}
import { assertEquals } from '../testHelper.js';
assertEquals(isEmpty({}), true)
assertEquals(isEmpty({ a: 1 }), false)
assertEquals(isEmpty({ z: 2, w: 4, y: 5 }), false)