xXCalleManXx

JavaSript Test #1

Sep 23rd, 2020 (edited)
962
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create a function that converts the array to the following object
  2. // It has to support unlimited amount of dots in the string and it has to be only one function
  3.  
  4. var arr = [
  5.   'customer.name',
  6.   'customer.age',
  7.   'customer.event.id',
  8.   'zz.yy.dd.aa',
  9.   'aa.yy.zz.dd.kk'
  10. ];
  11.  
  12.  
  13. var targetObject = {
  14.   customer: {
  15.     name: '',
  16.     age: '',
  17.     event: {
  18.       id: ''
  19.     }
  20.   },
  21.   zz: {
  22.     yy: {
  23.       dd: {
  24.         aa: ''
  25.       }
  26.     }
  27.   },
  28.   aa: {
  29.     yy: {
  30.       zz: {
  31.         dd: {
  32.           kk: '',
  33.         }
  34.       }
  35.     }
  36.   }
  37. }
RAW Paste Data