Find the available products

Take your time, follow the code and check your understanding.

The codeAPI transformations

Example checks

INPUT
[
  {
    "model": "A",
    "inStock": true
  },
  {
    "model": "B",
    "inStock": false
  }
]
EXPECTED
[
  {
    "model": "A",
    "inStock": true
  }
]
INPUT
[]
EXPECTED
[]
Your answer5 min · no timer

Implement solve(rows) and return a value. The example checks are visible. JavaScript runs in an isolated, network-blocked worker with a 2-second limit.

Show solution and explanation

filter keeps each record whose inStock field is true.

function solve(rows) {
  return rows.filter(row => row.inStock);
}