Last active
January 20, 2016 21:57
-
-
Save tinybike/65c88ff284ec71058099 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
| #!/usr/bin/env node | |
| var data = require('./150-override'); | |
| var searchTarget = { | |
| key: "level", | |
| value: "FLOOR" | |
| }; | |
| function traverseWrapper(node, search) { | |
| var searchResults = []; | |
| var totalSensorCount = 0; | |
| (function traverse(node, search) { | |
| if (node.childFacilities && node.childFacilities.constructor === Array && | |
| node.childFacilities.length) { | |
| for (var i = 0, n = node.childFacilities.length; i < n; ++i) { | |
| if (node.childFacilities[i] && | |
| node.childFacilities[i].constructor === Object && | |
| node.childFacilities[i][search.key] === search.value && | |
| node.childFacilities[i].state === "NJ") { // checks for NJ address specifically | |
| if (searchResults.indexOf(node.childFacilities[i].fullAddress) === -1) { | |
| searchResults.push(node.childFacilities[i].fullAddress); | |
| } | |
| if (node.childFacilities[i].sensorCount) { | |
| totalSensorCount += node.childFacilities[i].sensorCount; | |
| } | |
| } | |
| traverse(node.childFacilities[i], search); | |
| } | |
| } | |
| })(node, search); | |
| return {searchResults: searchResults, totalSensorCount: totalSensorCount}; | |
| } | |
| var traversed = traverseWrapper(data, searchTarget); | |
| console.log("results:", traversed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment