Advertisement
Marin171

JS

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