Skip to content

Instantly share code, notes, and snippets.

@asabaylus
Created November 18, 2011 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asabaylus/1375412 to your computer and use it in GitHub Desktop.
Save asabaylus/1375412 to your computer and use it in GitHub Desktop.
Get GUID from User Name
var users = {
"a54bca8764-13bx5-8nln8s-0ga7d" : {
"name" : "Louise Voress",
"type" : "Committee",
"primarynominator" : "Dorrie Hutchison",
"reviewer1" : {"name" : "Tom Jones", "grade" : "A", "comments" : "", "status" : "Saved"},
"reviewer2" : {"name" : "Lucy Young", "grade" : "A", "comments" : "", "status" : "Saved"},
"adjudicator" : {"name" : "Steven Taylor", "recommendation" : "Yes", "comments" : "", "status" : "Saved"},
"os" : [
{"name" : "Kevin Joseph", "vote" : "Yes", "comments" : "", "status" : "Saved"},
{"name" : "Matt Duncan", "vote" : "Yes", "comments" : "", "status" : "Saved"},
{"name" : "Joanna Lit", "vote" : "Yes", "comments" : "", "status" : "Saved"}
],
"oschair" : {"decision" : "Yes", "comments" : "", "status" : "Saved"}
},
"efg-fa346y-979nj992-ga6331ohh" : {
"name" : "Joanna Lit",
"type" : "Technical Division",
"primarynominator" : "Sam Ryan",
"reviewer1" : {"name" : "David La", "grade" : "", "comments" : "", "status" : "Recused"},
"reviewer2" : {"name" : "Bob Hall", "grade" : "A", "comments" : "", "status" : "Saved"},
"adjudicator" : {"name" : "Walter Johnson", "recommendation" : "Yes", "comments" : "", "status" : "Saved"},
"os" : [
{"name" : "Bill Stewert", "vote" : "Yes", "comments" : "", "status" : "Saved"},
{"name" : "Jeffrey Dustin", "vote" : "Yes", "comments" : "", "status" : "Saved"},
{"name" : "Tom Brady", "vote" : "Yes", "comments" : "", "status" : "Saved"}
],
"oschair" : {"decision" : "Yes", "comments" : "", "status" : "Saved"}
}
}
// loops over the key value pairs and prints
// them to the console. for education only
// code is not required
function printObject(o){
$.each(o, function(key, value){
console.log(key, value);
});
}
// takes users full name, returns matching user id
function getIdFromName(v){
var id;
$.each(obj, function(key, value){
if (v === value.name) {
id = key;
return;
}
});
return id;
};
console.log( getIdFromName("Louise Voress") );
console.log( getIdFromName("Joanna Lit") );
printObject(users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment