SHARE
TWEET

Untitled

a guest Aug 22nd, 2015 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let userFields = {
  2.     id: {
  3.         dbFields: 'id',
  4.     },
  5.     email: {
  6.         dbFields: 'email',
  7.     },
  8.     first_name: {
  9.         dbFields: 'first_name',
  10.     },
  11.     last_name: {
  12.         dbFields: 'last_name',
  13.     },
  14.     name: {
  15.         dbFields: ['first_name', 'last_name'],
  16.         resolve: user =>
  17.             [user.first_name, user.last_name]
  18.             .filter(n => n.length)
  19.             .join(' '),
  20.     }
  21. };
  22.  
  23. let selectFields = ['name', 'first_name', 'email'];
  24.  
  25. function concat(arrays) {
  26.     return [].concat.apply([], arrays);
  27. }
  28.  
  29. function uniquify(array) {
  30.     let s = new Set(array);
  31.     return Array.from(s);
  32. }
  33.  
  34. var dbFieldsPerSelect =
  35.     selectFields
  36.     .map(name => userFields[name].dbFields);
  37.  
  38. var dbFields = uniquify(concat(dbFieldsPerSelect));
  39.  
  40. console.log(dbFields);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top