bebo231312312321

Untitled

Jun 17th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class JobOffers {
  2.     constructor(employer, position) {
  3.       this.employer = employer;
  4.       this.position = position;
  5.       this.jobCandidates = [];
  6.     }
  7.     jobApplication(candidates){
  8.         let names = []
  9.         candidates.forEach(line => {
  10.             let [name, education,yearsExperience] = line.split('-')
  11.  
  12.             yearsExperience=Number(yearsExperience)
  13.  
  14.             let findName = this.jobCandidates.find(x => x.name === name)
  15.  
  16.             if(findName){
  17.                 if(findName.yearsExperience < yearsExperience){
  18.                     findName.yearsExperience = yearsExperience
  19.                 }
  20.             }
  21.             if(!findName){
  22.                 names.push(name)
  23.                 this.jobCandidates.push({name, education, yearsExperience})
  24.             }
  25.        
  26.            
  27.         });
  28.         return `You successfully added candidates: ${names.join(", ")}.`
  29.     }
  30.     jobOffer(chosenPerson) {
  31.         const [name, minimalExperience] = chosenPerson.split("-");
  32.         const minExp = Number(minimalExperience);
  33.         for (let jobCandidate of this.jobCandidates) {
  34.           if (jobCandidate.name === name) {
  35.             if (jobCandidate.yearsExperience < minExp) {
  36.               throw new Error(
  37.                 `${name} does not have enough experience as ${this.position}, minimum requirement is ${minExp} years.`
  38.               );
  39.             }
  40.             jobCandidate.yearsExperience = "hired";
  41.             return `Welcome aboard, our newest employee is ${name}.`;
  42.           }
  43.         }
  44.         throw new Error(`${name} is not in the candidates list!`);
  45.       }
  46.       salaryBonus(name){
  47.         const findName = this.jobCandidates.find(x=>x.name === name)
  48.  
  49.         if(!findName) throw new Error(`${name} is not in the candidates list!`)
  50.  
  51.         if(findName.education === 'Bachelor'){
  52.             return `${name} will sign a contract for ${this.employer}, as ${this.position} with a salary of $50,000 per year!`
  53.         }else if(findName.education === 'Master'){
  54.             return `${name} will sign a contract for ${this.employer}, as ${this.position} with a salary of $60,000 per year!`;
  55.         }else{
  56.             return `${name} will sign a contract for ${this.employer}, as ${this.position} with a salary of $40,000 per year!`;
  57.         }
  58.       }
  59.  
  60.       candidatesDatabase(){
  61.  
  62.         if(this.jobCandidates.length === 0 ) throw new Error("Candidate Database is empty!")
  63.  
  64.         let printResult = `Candidates list:`
  65.         let sorted = this.jobCandidates.sort((a,b)=>a.name.localeCompare(b.name))
  66.         sorted.forEach(candidates => printResult+=`\n${candidates.name}-${candidates.yearsExperience}`)
  67.         return printResult
  68.       }
  69. }
Add Comment
Please, Sign In to add comment