Advertisement
bebo231312312321

Untitled

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