JS Built-ins
TypeScriptintermediate

Advanced β€” zipWith<T, U, R>

πŸ“– Usage Example
zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)   // β†’ [5, 7, 9]

zipWith combines two arrays element-by-element using a provided combining function.

Advanced: zipWith

Challenge: Implement zipWith<T, U, R>(a: T[], b: U[], fn: (x: T, y: U) => R): R[] combining two arrays element-wise using a function.

zipWith([1,2,3], [4,5,6], (a,b) => a + b)  // β†’ [5, 7, 9]
πŸ’‘ Hints (1)
  • β€’ Like zip, but apply fn to each pair instead of wrapping in a tuple.