×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Khalil Johnson
Added: Dec 29, 2014 5:40 AM
Views: 13
Tags: no tags
Traverse Object Property Names to collect the information associated to them.
Parsing through an object.
  1. // Iterate through the localizedRuleNames in ruleResults and
  2. // return an array of their strings.
  3. function ruleList(results) {
  4.     // Your code goes here!
  5.     var keyNames = Object.keys(results.formattedResults.ruleResults);
  6.     var keyName = "localizedRuleName";
  7.     var contents = [];
  8.     for(i in keyNames){
  9.         var branch = results.formattedResults.ruleResults[keyNames[i]];
  10.         var nestedKeyNames = Object.keys(branch);
  11.         for(j in nestedKeyNames) {
  12.             var nestedBranch = branch[nestedKeyNames[j]];
  13.             if (nestedKeyNames[j] === keyName) {
  14.                contents.push(branch[nestedKeyNames[j]]);
  15.             }
  16.         }
  17.     }
  18.     return contents;
  19. }
  20.  
  21. // Iterate through pageStats in the psiResults object and
  22. // return the total number of bytes to load the website.
  23. function totalBytes(results) {
  24.     // Your code goes here!
  25.     var keyNames = Object.keys(results.pageStats);
  26.     var keyName = "Byte";
  27.     var bytes = 0;
  28.     for(i in keyNames){
  29.         if (keyNames[i].search(keyName) != -1) {
  30.             bytes += parseInt(results.pageStats[keyNames[i]]);
  31.         }
  32.     }
  33.     return bytes;
  34. }
  35.