Last active
September 3, 2017 00:21
-
-
Save imkrish/16be07147836165bc61f49c3036576ce to your computer and use it in GitHub Desktop.
06-prop.js
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 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