Knowee
Questions
Features
Study Tools

Problem statementSend feedbackSuppose you have a list of employees in a company, and each employee is represented as an object with the following properties:"id" - a unique identifier for the employee"name" - the employee's name"department" - the department the employee works in"salary" - the employee's current salaryObjectives:You want to make a modification to the list of employees to reflect a recent company-wide salary increase. You have been provided with the following information:Salaries for employees in the "sales" department should be increased by 10%.Salaries for employees in the "engineering" department should be increased by 15%.Salaries for employees in all other departments should be increased by 5%.You need to write a function "increaseSalaries" that takes an array of employee objects and returns a new array of employee objects where each employee's salary has been updated based on their department. The original array of employees should be left unchanged.

Question

Problem statementSend feedbackSuppose you have a list of employees in a company, and each employee is represented as an object with the following properties:"id" - a unique identifier for the employee"name" - the employee's name"department" - the department the employee works in"salary" - the employee's current salaryObjectives:You want to make a modification to the list of employees to reflect a recent company-wide salary increase. You have been provided with the following information:Salaries for employees in the "sales" department should be increased by 10%.Salaries for employees in the "engineering" department should be increased by 15%.Salaries for employees in all other departments should be increased by 5%.You need to write a function "increaseSalaries" that takes an array of employee objects and returns a new array of employee objects where each employee's salary has been updated based on their department. The original array of employees should be left unchanged.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a step-by-step solution in JavaScript:

  1. First, define the function increaseSalaries that takes an array of employee objects as an argument:
function increaseSalaries(employees) {
  1. Inside the function, use the map method to create a new array of employee objects. The map method creates a new array with the results of calling a provided function on every element in the array it was called upon.
    return employees.map(employee => {
  1. Inside the map method, use a switch statement to check the department of each employee and increase their salary accordingly:
        switch (employee.department) {
            case 'sales':
                employee.salary *= 1.10;
                break;
            case 'engineering':
                employee.salary *= 1.15;
                break;
            default:
                employee.salary *= 1.05;
        }
  1. After the switch statement, return the modified employee object:
        return employee;
    });
}
  1. The complete function should look like this:
function increaseSalaries(employees) {
    return employees.map(employee => {
        switch (employee.department) {
            case 'sales':
                employee.salary *= 1.10;
                break;
            case 'engineering':
                employee.salary *= 1.15;
                break;
            default:
                employee.salary *= 1.05;
        }
        return employee;
    });
}

This function will return a new array of employee objects with updated salaries, leaving the original array unchanged.

This problem has been solved

Similar Questions

Design a structure in C to represent an employee's information, including their name, employee ID, department, and salary. Additionally, write a program that allows users to input employee data, display employee information, and update an employee's salary. write a code for demonstrating the implementation of the structure and program functionalities.input and output Enter employee details:Enter employee name: John DoeEnter employee ID: 101Enter department: SalesEnter salary: 50000Employee Information:Name: John Employee ID: 101 Department:Sales Salary: 50000.00Enter new salary: 55000Salary updated successfully.Updated Employee Information:Name: JohnEmployee ID: 101Department: SalesSalary: 55000.00

For the Employee Class Program in this tutorial, what if we need the capability to update the salary for employees? What information is needed to perform this task, and what code segment implements obtaining it in a method?a.)Employees file information and the new salarydef upd_salary(): employees = read_employees() new_sal = input("Enter the new salary of the employee: ")b.)The new salarydef upd_salary(employees): new_sal = input("Enter the new salary of the employee: ")c.)Employee iddef upd_salary(employees): empid = input("Enter the employee ID: ")d.)Employee id and the new salarydef upd_salary(employees): empid = input("Enter the employee ID: ") new_sal = input("Enter the new salary of the employee: ")

Salaries ___ since she became the CEO of our company.a) had increasedb) increasedc) have increasedd) are increasing

Define a class “employee” having employee id, name and salary use accept and to-string method to display and create n employee’s data and find the total salary of all employees and find the name of the employee who is having maximum salary.

(a) Create a trigger, which verify that updated salary of employee must begreater than his/her previous salary(b) Create a trigger, which verify that for the department 2, the number ofemployees should not exceed than 5.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.