File size: 1,207 Bytes
6dc9a51
 
 
1
2
3
4
{"completion_code": "\n  for (const item of items) {\n    if (predicate(item)) {\n      matching.push(item);\n    } else {\n      remaining.push(item);\n    }\n  }\n  return [matching, remaining];\n}", "incomplete_function_context": "function partition<T, S extends T>(\n  items: readonly T[],\n  predicate: (item: T) => item is S\n): [S[], Exclude<T, S>[]] {\n  const matching: S[] = [];\n  const remaining: Exclude<T, S>[] = [];"}
{"incomplete_function_context": "function uniqueBy<T, K extends keyof T>(\n  items: readonly T[],\n  key: K\n): T[] {\n  const seen = new Set<T[K]>();\n  const result: T[] = [];", "completion_code": "\n  for (const item of items) {\n    const value = item[key];\n    if (!seen.has(value)) {\n      seen.add(value);\n      result.push(item);\n    }\n  }\n  return result;\n}"}
{"completion_code": "\n  for (const item of updates) {\n    merged.set(item.id, item);\n  }\n  return Array.from(merged.values());\n}", "incomplete_function_context": "function mergeById<T extends { readonly id: string }>(\n  existing: readonly T[],\n  updates: readonly T[]\n): T[] {\n  const merged = new Map<string, T>();\n  for (const item of existing) {\n    merged.set(item.id, item);\n  }"}