Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. const R = require('ramda')
  2.  
  3. const customers = [
  4. { id: 1, name: 'Bill', age: 45, title: 'MR.', email: 'bill@email.com', phoneNumber: 01, company: 'ABC Comp' },
  5. { id: 2, name: 'Diane', age: 59, email: 'diane@email.com', phoneNumber: 02 },
  6. { id: 3, name: 'Krish', age: 26, title: 'MR.', phoneNumber: 03, company: 'Apricot' }
  7. ]
  8.  
  9. // const titleProp = R.prop('title')
  10. // const nameProp = R.prop('name')
  11. // const companyProp = R.prop('company')
  12. // const emailProp = R.prop('email')
  13.  
  14. // [
  15. // 'MR. - Bill - ABC Comp - bill@email.com',
  16. // 'undefined - Diane - undefined - diane@email.com',
  17. // 'MR. - Krish - Apricot - undefined'
  18. // ]
  19.  
  20. const titleProp = R.propOr('', 'title')
  21. const nameProp = R.propOr('', 'name')
  22. const companyProp = R.propOr('No Company', 'company')
  23. const emailProp = R.propOr('No Email', 'email')
  24.  
  25. const getDetails = (title, name, company, email) => `${title} - ${name} - ${company} - ${email}`
  26. const getCustomerDetails = R.converge(getDetails, [titleProp, nameProp, companyProp, emailProp])
  27. const customerDetailsStringList = R.map(getCustomerDetails)
  28. const result = customerDetailsStringList(customers)
  29. console.log(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement