Created
October 14, 2015 00:34
-
-
Save cacheflow/f647dcff7cc910129624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var cities = []; | |
var underscore = require("underscore"); | |
var data = fs.readFileSync("public/retailers.json", "utf-8", function(result, error) { | |
if(!error) { | |
return result; | |
} | |
}); | |
data = JSON.parse(data); | |
for(var i in data) { | |
var uniqueCities; | |
cities.push(data[i].city); | |
} | |
var uniqueCities = underscore.unique(cities); | |
var sortedCities = underscore.unique(uniqueCities); | |
var file = fs.createWriteStream('cities.txt'); | |
file.on("error", function(err) { | |
throw err; | |
}); | |
fs.writeFile("cities.json", JSON.stringify(sortedCities), function(err) { | |
if(err) { | |
console.log(err); | |
} | |
else { | |
console.log("File saved"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment