Advertisement
tonysamperi

017 - Reflection model

Aug 24th, 2022
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.48 KB | Source Code | 0 0
  1. function createReflectionModel(source) {
  2.   if (typeof source === typeof {}) {
  3.       const target = Array.isArray(source)
  4.           ? []
  5.           : {};
  6.       let i = -1;
  7.       Object.keys(source).forEach((key) => {
  8.            target[key] =
  9.              createReflectionModel(source[key])
  10.       });
  11.  
  12.       return target;
  13.   }
  14.   else {
  15.     return void 0;
  16.   }
  17. }
  18.  
  19. createReflectionModel({a: 2, b: 3, c: {d: 4}});
  20.  
  21. // Ouput
  22. // {a: undefined, b: undefined, c: {d: undefined}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement