Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cars(data) {
- const result = {};
- const funcs = {
- create: (name, inherit, name2) => {
- if (inherit) {
- result[name] = Object.create(result[name2]);
- } else {
- result[name] = {};
- }
- },
- set: (name, key, prop) => (result[name][key] = prop),
- print: (name) => {
- let output = [];
- for (let key in result[name]) {
- output.push(`${key}:${result[name][key]}`);
- }
- console.log(output.join(','));
- },
- };
- data.forEach((x) => {
- let [action, key, prop, value] = x.split(' ');
- let command = funcs[action];
- command(key, prop, value);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement