Skip to content

Instantly share code, notes, and snippets.

@runk
Created June 25, 2015 00:54
Show Gist options
  • Save runk/9d8b52f1bde833947dd0 to your computer and use it in GitHub Desktop.
Save runk/9d8b52f1bde833947dd0 to your computer and use it in GitHub Desktop.
fs = require 'fs'
data = fs.readFileSync "#{__dirname}/../data/geo.txt", 'utf8'
data = data.toString().split '\n'
countryCounter = (countryCode) ->
counter = 0
for line in data when line
line = line.split '\t'
# GEO_FIELD_MIN, GEO_FIELD_MAX, GEO_FIELD_COUNTRY
# line[0], line[1], line[3]
if line[3] == countryCode then counter++
return counter
exports.countryCounter = (countryCode) ->
return null unless countryCode
return countryCounter countryCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment