Advertisement
Onesible

01-Space-Exploration-Crew-Management

Apr 8th, 2025
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let n = Number(arr.shift());
  3.     let crew = new Map();
  4.  
  5.     for (let i = 0; i < n; i++) {
  6.         let [name, section, skills] = arr.shift().split(' ');
  7.         crew.set(name, { section, skills: skills.split(',') });
  8.     }
  9.     console.log(crew)
  10.  
  11.     while (arr[0] !== 'End') {
  12.         let tokens = arr.shift().split(' / ');
  13.         let command = tokens[0];
  14.         let name = tokens[1];
  15.        
  16.         switch (command) {
  17.             case 'Perform':
  18.                 let section = tokens[2];
  19.                 let skill = tokens[3];
  20.                
  21.                 if (crew.get(name).section === section && crew.get(name).skills.includes(skill)) {
  22.                     console.log(`${name} has successfully performed the skill: ${skill}!`);
  23.                 } else {
  24.                     console.log(`${name} cannot perform the skill: ${skill}.`);
  25.                 }
  26.                 break;
  27.                
  28.             case 'Transfer':
  29.                 let newSection = tokens[2];
  30.                 crew.get(name).section = newSection;
  31.                 console.log(`${name} has been transferred to: ${newSection}`);
  32.                 break;
  33.                
  34.             case 'Learn Skill':
  35.                 let newSkill = tokens[2];
  36.                
  37.                 if (crew.get(name).skills.includes(newSkill)) {
  38.                     console.log(`${name} already knows the skill: ${newSkill}.`);
  39.                 } else {
  40.                     crew.get(name).skills.push(newSkill);
  41.                     console.log(`${name} has learned a new skill: ${newSkill}.`);
  42.                 }
  43.                 break;
  44.         }
  45.     }
  46.  
  47.     for (let [name, data] of crew) {
  48.         console.log(`Astronaut: ${name}, Section: ${data.section}, Skills: ${data.skills.sort().join(', ')}`);
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement