Advertisement
vvsvvs

Untitled

Sep 30th, 2022
966
0
122 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let data = [];
  3.  
  4.     let action = carsManipulator();
  5.  
  6.     for (const task of input) {
  7.         let [cmd, name, key, value] = task.split(' ');
  8.  
  9.         if (key == 'inherit') {
  10.             cmd += key;
  11.             key = value;
  12.         }
  13.  
  14.         action[cmd](name, key, value);
  15.  
  16.     }
  17.  
  18.     function carsManipulator() {
  19.  
  20.         let result = {
  21.             create: (name) => {
  22.                 data[name] = {};
  23.             },
  24.  
  25.             createinherit: (name, nameOfParent) => {
  26.                 let newObj = Object.create(data[nameOfParent]);
  27.                 data[name] = newObj;
  28.             },
  29.  
  30.             set: (name, key, value) => {
  31.               data[name][key] = value;
  32.             },
  33.  
  34.             print: (name) => {
  35.               let output = [];
  36.              
  37.               for (var prop in data[name]) {
  38.                 output.push(`${prop}:${data[name][prop]}`);
  39.               }
  40.                
  41.                 let s = output.join(',');
  42.  
  43.                 console.log(s);
  44.             }
  45.         }
  46.  
  47.         return result;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement