Created
July 14, 2018 13:50
-
-
Save nazreen/ff14d023fd98fa6060708f5dae438ab2 to your computer and use it in GitHub Desktop.
determine number of live promises by live politicians
This file contains 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
const politicians = require('./politicians.json') | |
const promises = require('./promises.json') // live promises | |
const result = { | |
promisesWithLivePoliticians: { | |
total: 0 | |
}, | |
promisesWithOfflinePoliticians: { | |
total: 0 | |
} | |
} | |
promises.forEach(promise => { | |
const politician = politicians.find(x => x.id === promise.politician_id) | |
const isLive = politician.live | |
if(isLive) { | |
result.promisesWithLivePoliticians.total++ | |
if (typeof result.promisesWithLivePoliticians[politician.name] === 'number') { | |
result.promisesWithLivePoliticians[politician.name]++ | |
} else { | |
result.promisesWithLivePoliticians[politician.name] = 0 | |
} | |
} else { | |
result.promisesWithOfflinePoliticians.total++ | |
if (typeof result.promisesWithOfflinePoliticians[politician.name] === 'number') { | |
result.promisesWithOfflinePoliticians[politician.name]++ | |
} else { | |
result.promisesWithOfflinePoliticians[politician.name] = 0 | |
} | |
} | |
}) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment