Skip to content

Instantly share code, notes, and snippets.

View joelcrocker's full-sized avatar

Joel Crocker joelcrocker

  • PagerDuty
  • Toronto, ON
View GitHub Profile
@hans
hans / zip.coffee
Created April 12, 2011 04:42
Haskell-esque `zip` and `zipWith`, ported to node.js / CoffeeScript
zip = (arr1, arr2) ->
basic_zip = (el1, el2) -> [el1, el2]
zip_with basic_zip, arr1, arr2
# I wrote two implementations of `zipWith`: one is iterative, and one is recursive. Feel free to do some benchmarks if you feel like it :)
# zip_with, iterative style
zip_with = (func, arr1, arr2) ->
min = Math.min arr1.length, arr2.length
ret = []