Skip to content

Instantly share code, notes, and snippets.

@emilhein
Last active March 5, 2018 11:32
Show Gist options
  • Save emilhein/f12fddd36e30c931def726144fa66449 to your computer and use it in GitHub Desktop.
Save emilhein/f12fddd36e30c931def726144fa66449 to your computer and use it in GitHub Desktop.
Functional ramda
const R = require('ramda')
let object = [{
Name: 'a',
Records: [{
Value: '1.2.3.4.5'
}],
Type: 'winner'
},
{
Name: 'c',
Records: [ { Value: '1.2.3.4.5.6.7.8.9' } ],
Type: 'winner'
},
{
Name: 'b',
Type : 'loser'
}
]
const isWinner = R.propEq('Type', 'winner')
const findWinners = R.filter(isWinner, R.__)
const hasFinalProp = R.propEq('Value', '1.2.3.4.5')
const unfold = input => R.any(hasFinalProp)(input.Records)
const findCorrectReccord = R.filter(unfold)
const findWishes = R.compose(findCorrectReccord, findWinners)
console.log(findWishes(object));
const appCNAMES = (appName, records) => {
const isCNAME = R.propEq("Type", "CNAME");
const filterForCNAME = R.filter(isCNAME, R.__);
const containsAppNameInRecord = input => R.contains(appName, R.prop("Value", input));
const satisfy = R.anyPass([containsAppNameInRecord]);
const checkResourceRecords = input => R.any(satisfy)(input.ResourceRecords);
const findAppRecords = R.filter(checkResourceRecords);
const doesDNSHaveCNAME = R.compose(findAppRecords, filterForCNAME, R.flatten)(records);
return doesDNSHaveCNAME
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment