Advertisement
bebo231312312321

Untitled

May 28th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cars(data) {
  2.   const result = {};
  3.  
  4.   const funcs = {
  5.     create: (name, inherit, name2) => {
  6.       if (inherit) {
  7.         result[name] = Object.create(result[name2]);
  8.       } else {
  9.         result[name] = {};
  10.       }
  11.     },
  12.     set: (name, key, prop) => (result[name][key] = prop),
  13.     print: (name) => {
  14.       let output = [];
  15.       for (let key in result[name]) {
  16.         output.push(`${key}:${result[name][key]}`);
  17.       }
  18.       console.log(output.join(','));
  19.     },
  20.   };
  21.  
  22.   data.forEach((x) => {
  23.     let [action, key, prop, value] = x.split(' ');
  24.     let command = funcs[action];
  25.     command(key, prop, value);
  26.   });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement