0 of 6 problems solved0%
3 of 6

Pluck Many

Relate two type parameters: an object type T and a key K with K extends keyof T. The return type T[K][] keeps element types precise. This pattern powers many safe property helpers.

function pluck<T, K extends keyof T>(items: T[], key: K): T[K][] {
  return items.map((i) => i[key]);
}

Use a simple loop or map at runtime.

Your Task

Return an array of values for a given property.

  • Implement function pluck<T, K extends keyof T>(items: T[], key: K): T[K][].
  • Read each property by key and collect values in order.
  • Do not mutate the input array.
  • Work for both strings and numbers in tests.