Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 customerDetailsStringList = R.map(getCustomerDetails)
- const result = customerDetailsStringList(customers)
- console.log(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement