Skip to content

Instantly share code, notes, and snippets.

@imkrish
Last active September 3, 2017 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/16be07147836165bc61f49c3036576ce to your computer and use it in GitHub Desktop.
Save imkrish/16be07147836165bc61f49c3036576ce to your computer and use it in GitHub Desktop.
06-prop.js
const R = require('ramda')
const customers = [
{ id: 1, name: 'Bill', age: 45, title: 'MR.', email: 'bill@email.com', phoneNumber: 01, company: 'ABC Comp' },
{ id: 2, name: 'Diane', age: 59, email: 'diane@email.com', phoneNumber: 02 },
{ id: 3, name: 'Krish', age: 26, title: 'MR.', phoneNumber: 03, company: 'Apricot' }
]
// const titleProp = R.prop('title')
// const nameProp = R.prop('name')
// const companyProp = R.prop('company')
// const emailProp = R.prop('email')
// [
// 'MR. - Bill - ABC Comp - bill@email.com',
// 'undefined - Diane - undefined - diane@email.com',
// 'MR. - Krish - Apricot - undefined'
// ]
const titleProp = R.propOr('', 'title')
const nameProp = R.propOr('', 'name')
const companyProp = R.propOr('No Company', 'company')
const emailProp = R.propOr('No Email', 'email')
const getDetails = (title, name, company, email) => `${title} - ${name} - ${company} - ${email}`
const getCustomerDetails = R.converge(getDetails, [titleProp, nameProp, companyProp, emailProp])
const getCustomerDetailsStringList = R.map(getCustomerDetails)
const result = getCustomerDetailsStringList(customers)
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment