Extracting a list of hyperlinks I need to produce a list objCollector with some results:

objCollector = []

      allRows.each () -&gt;
        obj =
          source: self.source
          url: ''
          host: ''

        currentTag = $(this)
        links = currentTag.find('a')
        getTextFromSpan = currentTag.find('span.lnk').text()
        extractedLink = links[0].attribs.href
        obj.url = self.baseUrl + extractedLink
        obj.host = getTextFromSpan

        objCollector.push obj


Instead of building the result by appending to an empty list, could this be done more elegantly by using something like map?
I just moved things around to make it a bit more readable. You can use the map function instead of each. The signature of map is as follows:


element in array
index of element
the array itself


I've added those parameters in the coffee script, but you could have easily done without them for a cleaner look. I assumed that self is some kind of global variable or variable available to the inner scope of the map.

See the Mozilla article on map. It's fantastic!

objCollector = allRows.map (element, index, context) -&gt;
  tag = $(element)

  text = tag.find('span.lnk').text()
  link = tag.find('a').first().attribs.href

  {
    source: self.source
    url: self.baseUrl + link
    host: text
  }