Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class JobOffers {
- constructor(employer, position) {
- this.employer = employer;
- this.position = position;
- this.jobCandidates = [];
- }
- jobApplication(candidates) {
- let names = candidates.reduce((acc, line) => {
- let [name, education, yearsExperience] = line.split('-'); yearsExperience = Number(yearsExperience)
- let findName = this.jobCandidates.find(x => x.name === name)
- if (findName) if (findName.yearsExperience < yearsExperience) findName.yearsExperience = yearsExperience;
- if (!findName) acc.push(name), this.jobCandidates.push({ name, education, yearsExperience })
- return acc;
- }, []); return `You successfully added candidates: ${names.join(", ")}.`
- }
- jobOffer(chosenPerson) {
- const [name, minimalExperience] = chosenPerson.split("-");
- const minExperience = Number(minimalExperience);
- for (let jobCandidate of this.jobCandidates) {
- if (jobCandidate.name === name) {
- if (jobCandidate.yearsExperience < minExperience) {
- throw new Error(`${name} does not have enough experience as ${this.position}, minimum requirement is ${minExperience} years.`);
- }
- jobCandidate.yearsExperience = "hired"; return `Welcome aboard, our newest employee is ${name}.`;
- }
- }
- throw new Error(`${name} is not in the candidates list!`);
- }
- salaryBonus(name) {
- const findName = this.jobCandidates.find(x => x.name === name)
- if (!findName) throw new Error(`${name} is not in the candidates list!`);
- const salary = findName.education === "Bachelor" ? "$50,000 per year" : findName.education === "Master" ? "$60,000 per year"
- : "$40,000 per year";
- return `${name} will sign a contract for ${this.employer}, as ${this.position} with a salary of ${salary}!`
- }
- candidatesDatabase() {
- if (this.jobCandidates.length === 0) throw new Error("Candidate Database is empty!");
- let p = `Candidates list:`
- p += this.jobCandidates.sort((a, b) => a.name.localeCompare(b.name))
- .map(c => `\n${c.name}-${c.yearsExperience}`)
- return p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement