Skip to content

Instantly share code, notes, and snippets.

@cdinu
Created March 8, 2014 22:39
Show Gist options
  • Save cdinu/9440102 to your computer and use it in GitHub Desktop.
Save cdinu/9440102 to your computer and use it in GitHub Desktop.
/**
Go to: https://developers.facebook.com/tools/explorer/
Then get access token: permissions, friends, current_location, hometown
FQL Query:
SELECT name, current_location.city, hometown_location.city
FROM user
WHERE uid in (SELECT uid2 FROM friend WHERE uid1=me())
Copy and paste, clean it, or modify the fields in the for statement below to match directly FQL JSON output
**/
var data = [
/* Data was cut for privacy reasons */
/* .... */
{n: "Paul Balogh", c: "Bucharest", h:"Brasov"},
{n: "Cristian Dinu", c: "Bucharest", h:"Pitesti"},
/* .... */
/* .... */
/* .... */
/* .... */
/* .... */
];
var born_in_bucharest = 0;
var living_in_bucharest = 0;
var born_and_living = 0;
var not_born_and_living = 0;
var total = 0;
var current_cities = {};
var home_cities = {};
var home_cities_for_bucharest_guys = {};
for(i = 0; i < data.length; i++) {
var gigi = data[i];
total++;
if(gigi.h == "Bucharest") {
born_in_bucharest++;
}
if (gigi.c == "Bucharest") {
living_in_bucharest++;
home_cities_for_bucharest_guys[gigi.h] = home_cities_for_bucharest_guys[gigi.h] ? home_cities_for_bucharest_guys[gigi.h] + 1: 1;
if(gigi.h == "Bucharest") {
born_and_living++;
}
else {
not_born_and_living++;
}
}
current_cities[gigi.c] = current_cities[gigi.c] ? current_cities[gigi.c] + 1: 1;
home_cities[gigi.h] = home_cities[gigi.h] ? home_cities[gigi.h] + 1: 1;
}
console.log("born_in_bucharest:", born_in_bucharest)
console.log("living_in_bucharest:", living_in_bucharest)
console.log("born_and_living:", born_and_living)
console.log("not_born_and_living:", not_born_and_living)
console.log("total:", total)
console.log("current_cities:", current_cities)
console.log("home_cities:", home_cities)
console.log("home_cities_for_bucharest_guys:", home_cities_for_bucharest_guys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment