Created
August 24, 2016 18:00
-
-
Save tomprogers/0d7e7b9354e685b1371d554f49208e35 to your computer and use it in GitHub Desktop.
algorithm for counting the names and datatypes of properties of a set of (hopefully) similarly-shaped object
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
// before running this, define ITEMS as an array of objects whose props you wish to examine | |
items.reduce((tallies, asset) => { | |
Object | |
.keys(asset) | |
.forEach((prop) => { | |
if(tallies.hasOwnProperty(`${prop} (${typeof asset[prop]})`)) { | |
console.log(`has ${prop} (${typeof asset[prop]})`); | |
tallies[`${prop} (${typeof asset[prop]})`] += 1; | |
} else { | |
console.log(`no has ${prop} (${typeof asset[prop]})`); | |
tallies[`${prop} (${typeof asset[prop]})`] = 1; | |
} | |
}); | |
return tallies; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment