Last active
November 8, 2018 21:38
-
-
Save beall49/761991f9c8f04a2b6ed10e8231e783ca 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
| /** building.json | |
| { | |
| "results" = [ { | |
| "attributes": { | |
| "BUILDING": "B041", | |
| ..... | |
| } | |
| }, | |
| { | |
| "attributes": { | |
| "BUILDING": "B071", | |
| .... | |
| }, | |
| { | |
| "attributes": { | |
| "BUILDING": "B111", | |
| .... | |
| } | |
| }, | |
| { | |
| "attributes": { | |
| "BUILDING": "B111" | |
| ..... | |
| } | |
| }] | |
| } | |
| */ | |
| const buildingJson = require('./building'); | |
| const buildingObject = (id) => { | |
| return { | |
| id: id, | |
| idNumber: id.substring(1), | |
| }; | |
| }; | |
| const reduceBuildings = (buildings) => { | |
| return buildings.reduce((groups, building) => { | |
| const idNumber = building.idNumber; | |
| const id = building.id; | |
| const group = groups.find(g => g.idNumber === idNumber); | |
| if (group) { | |
| return groups; | |
| } | |
| groups.push({ | |
| id: id, | |
| idNumber: idNumber, | |
| }); | |
| return groups; | |
| }, []); | |
| }; | |
| const buildings = (buildingJson.results.map(b => buildingObject(b.attributes.BUILDING))); | |
| const buildingNumbers = reduceBuildings(buildings); | |
| console.log(JSON.stringify(buildingNumbers)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment