← Commure Interview Insights

Commure·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Coding round at Commure for a frontend role. The problem was a follow-up to a Sims-style filtering function, extending it to handle multiple conditions with a logical AND. Type safety was the main thing they were pushing on.

Questions Asked (1)

Q1

Extend a filter function to accept multiple conditions (each comparing a single field like age, occult type, or salary) and return only the objects satisfying all of them. How do you design a type-safe, scalable representation for this?

Algorithms & Data StructuresTechnical Trade-offsData Modeling
Author's notes

The tricky part wasn't the filtering logic itself, that's just a reduce or every call.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the filter should accept multiple conditions, each on a single field, and return objects that satisfy all (AND logic). Then propose a type-safe representation, such as a discriminated union of condition objects keyed by field name, and a generic filter function that infers the object type and validates conditions at compile time. Discuss scalability by allowing easy addition of new fields and operators without modifying the core filter logic.

Pro tip: Mention that you'd use TypeScript's mapped types and conditional types to ensure each condition's value type matches the field's type, preventing runtime errors. Also, highlight that you'd design for extensibility by separating condition definition from evaluation, perhaps using a registry pattern.

1. Clarify requirements and constraints

Ask if conditions are always ANDed, if OR/NOT logic is needed, and what operators (equality, range, etc.) must be supported. Confirm the data shape and whether fields are optional.

2. Define a type-safe condition representation

Propose a discriminated union where each condition specifies a field (keyof T) and an operator, with the value type tied to the field's type using generics. For example: type Condition<T> = { [K in keyof T]: { field: K; operator: Operator; value: T[K] } }[keyof T].

3. Design the filter function signature

Write a generic function: function filter<T>(items: T[], conditions: Condition<T>[]): T[]. Ensure it returns the same type T and that conditions are validated at compile time.

4. Implement evaluation logic

For each item, check all conditions using a switch on operator or a lookup map. Ensure short-circuit evaluation for performance. Keep the logic pure and testable.

5. Discuss scalability and trade-offs

Explain how to add new fields or operators without changing the filter function (e.g., via a condition evaluator registry). Mention potential performance concerns with many conditions and how to optimize (e.g., indexing, early exit).

Key Points to Mention

  • Use TypeScript generics and mapped types to enforce that condition values match field types.
  • Discriminated unions for conditions enable exhaustive operator handling and type safety.
  • Separate condition definition from evaluation to allow extensibility (e.g., plugin operators).
  • Consider performance: short-circuit AND evaluation, avoid unnecessary iterations.
  • Handle edge cases: empty conditions array (return all), missing fields, null/undefined values.
  • Mention alternative approaches like using a query builder or predicate functions, and trade-offs.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.