Skip to content
Jobless Busters
Runs testsBasic5–10 min

Warm-up: checking input

Checking input: you receive unknown. Write a check that it's an object, has a non-empty string identifier, and isn't null or an array. Compare with parseLookupArgs only after your own attempt. Explain why as {id:string} isn't such a check.

The function parseLookupArgs(value) returns { id } or throws an error.

  • Check data at runtime
  • Tell a type cast from validation
The 3 tests

Tests written from the warm-up task. The reference implementation also rejects extra fields and ids longer than 100 characters — the tests don't require that.

returns { id } for a valid object

JavaScript
assert.deepEqual(parseLookupArgs({ id: 'A' }), { id: 'A' });

rejects null, arrays and primitive values

JavaScript
for (const value of [null, [], ['A'], 'A', 7, undefined]) {
  assert.throws(() => parseLookupArgs(value));
}

rejects an empty, non-string or missing identifier

JavaScript
for (const value of [{ id: '' }, { id: 7 }, {}]) {
  assert.throws(() => parseLookupArgs(value));
}

Source: AI & Agents — practice tasks — An exercise written for the study programme, not a confirmed interview task.

JavaScript · runs in a Web Worker in your browser

Tab indents · Esc, then Tab, leaves the editor · ⌘/Ctrl + Enter runs the tests · Your code is saved in this browser.

Run the tests to check your solution. 3 predefined tests.

Stuck? Hints go from gentle to specific.

Give it a real try first — the solution is most useful after you've struggled a bit.