Advertisement
bebo231312312321

Untitled

Jun 18th, 2023
111
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 = candidates.reduce((acc, line) => {
  9.       let [name, education, yearsExperience] = line.split('-'); yearsExperience = Number(yearsExperience);
  10.       let findName = this.jobCandidates.find(x => x.name === name);
  11.       if (findName) if (findName.yearsExperience < yearsExperience) findName.yearsExperience = yearsExperience;
  12.       if (!findName) acc.push(name), this.jobCandidates.push({ name, education, yearsExperience })
  13.       return acc;
  14.     }, []); return `You successfully added candidates: ${names.join(", ")}.`
  15.   }
  16.   jobOffer(chosenPerson) {
  17.     const [name, minimalExperience] = chosenPerson.split("-");
  18.     const minExperience = Number(minimalExperience);
  19.     for (let jobCandidate of this.jobCandidates) {
  20.       if (jobCandidate.name === name) {
  21.         if (jobCandidate.yearsExperience < minExperience) {
  22.           throw new Error(`${name} does not have enough experience as ${this.position}, minimum requirement is ${minExperience} years.`);
  23.         }
  24.         jobCandidate.yearsExperience = "hired"; return `Welcome aboard, our newest employee is ${name}.`;
  25.       }
  26.     }
  27.     throw new Error(`${name} is not in the candidates list!`);
  28.   }
  29.   salaryBonus(name) {
  30.     const findName = this.jobCandidates.find(x => x.name === name);
  31.     if (!findName) throw new Error(`${name} is not in the candidates list!`);
  32.     const salary = findName.education === "Bachelor" ? "$50,000 per year" : findName.education === "Master" ? "$60,000 per year"
  33.       : "$40,000 per year";
  34.     return `${name} will sign a contract for ${this.employer}, as ${this.position} with a salary of ${salary}!`
  35.   }
  36.   candidatesDatabase(){
  37.           if(this.jobCandidates.length === 0 ) throw new Error("Candidate Database is empty!")
  38.           let p = `Candidates list:`
  39.           let sorted = this.jobCandidates.sort((a,b)=>a.name.localeCompare(b.name)).forEach(c => p+=`\n${c.name}-${c.yearsExperience}`)
  40.           return p;
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement