12345678910111213141516171819202122232425262728293031323334 |
- storeLocations1 = [
- 'Orlando'
- 'Winter Park'
- 'Sanford'
- ]
- # Beware, this doesn't compile correctly:
- # storeLocations.forEach(location, index) ->
- # It uses it as a forEach(location, index) call with a () => {} callback
- # So be sure to add the space.
- storeLocations1.forEach (location, index) ->
- console.log "Location #{index}: #{location}"
- # Or use something more idiomatic:
- for location, index in storeLocations1
- console.log "Location #{index}: #{location}"
- # List comprehensions
- console.log "Location #{index}: #{location}" for location, index in storeLocations1
- # In this case, the parentheses are essential
- storeLocations2 = ("#{loc}, FL" for loc in storeLocations1)
- # Without them, the whole "storeLocations = ..." part is run for each loc.
- console.log storeLocations2
- geoLocate = (loc) ->
- return "#{loc}, USA"
- # Applying a filter to a list comprehension
- console.log (geoLocate(loc) for loc in storeLocations1 when loc isnt 'Sanford')
- storeLocations3 = (loc for loc in storeLocations1 when loc isnt 'Sanford')
- console.log(storeLocations3)
|