JavaScript Surgeons - Array[ ]
Visualize team management and project execution! Here’s how JavaScript array methods can conceptually represent different aspects of forming and managing a software development team:
1. Team introduction - map()
The company recruited 12 members for this project and introduced them to the client. They have been onboarded and are ready to contribute.
map()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
devTeam.map(teamMember => console.log(teamMember));
//==============================console=================================
//Nirav
//Suraj
//Amit
//Ruthvik
//Gayatri
//Tarun
//John
//Michael
//Sanjay
//Manohar
//Ranjith
//Suman
2. Recruiting new team members - push()
Planning to recruit two more fresher candidates who will be trained and mentored for various roles, contributing to the project's success and growth. This will further strengthen the team and help in meeting our development goals.
push()
//Create a new team member variable
let newDeveloper = "Ganesh";
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//push new developer into current dev team
devTeam.push(newDeveloper);
//console
console.log(devTeam)
//==============================console=================================
//(13) ['Nirav', 'Suraj', 'Amit', 'Ruthvik', 'Gayatri', 'Tarun', 'John', 'Michael', 'Sanjay', 'Manohar', 'Ranjith', 'Suman', 'Ganesh']
3. Arrange employee names in alphabetical order - sort()
Here’s the list of all development team members’ names and arranging names in alphabetical order.
sort()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//arranging rames in general alphabet order
const orderNames = devTeam.sort()
console.log(orderNames)
//==============================console=================================
//['Amit', 'Gayatri', 'John', 'Manohar', 'Michael', 'Nirav', 'Ranjith', 'Ruthvik', 'Sanjay', 'Suman', 'Suraj', 'Tarun']
4. Arrange employee names in reverse alphabetical order - sort(), reverse()
Arrange all employee names in reverse alphabetical order.
sort(), reverse()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//arranging rames in reverse-alphabet order
const reverseNames = devTeam.sort().reverse();
console.log(reverseNames)
//==============================console=================================
//[ 'Tarun', 'Suraj', 'Suman', 'Sanjay', 'Ruthvik', 'Ranjith', 'Nirav', 'Michael', 'Manohar', 'John', 'Gayatri', 'Amit' ]
5. Calculating all employee’s monthly salaries - reduce()
reduce()
//Create devTeam array object
let devTeam = [
{ name: "Nirav", salary: "50000" },
{ name: "Suraj", salary: "25000" },
{ name: "Amit", salary: "87000" },
{ name: "Ruthvik", salary: "23000" },
{ name: "Gayatri", salary: "18000" },
{ name: "Tarun", salary: "57000" },
{ name: "John", salary: "62000" },
{ name: "Michael", salary: "35000" },
{ name: "Sanjay", salary: "56000" },
{ name: "Manohar", salary: "44000" },
{ name: "Ranjith", salary: "88000" },
{ name: "Suman", salary: "95000" }
]
//colculating month salaries expenditures
const monthlySalaries = devTeam.reduce((accumulator, employee) => accumulator + Number(employee.salary), 0)
console.log(monthlySalaries)
//==============================console=================================
//640000
6. The company wants to increase salaries by 5% - forEach()
Official Employee ID assignment is required for ODC access and internal assistance within the company. This ID will serve as a unique identifier for all official purposes.
forEach()
//Create devTeam array object
let devTeam = [
{ name: "Nirav", salary: "50000" },
{ name: "Suraj", salary: "25000" },
{ name: "Amit", salary: "87000" },
{ name: "Ruthvik", salary: "23000" },
{ name: "Gayatri", salary: "18000" },
{ name: "Tarun", salary: "57000" },
{ name: "John", salary: "62000" },
{ name: "Michael", salary: "35000" },
{ name: "Sanjay", salary: "56000" },
{ name: "Manohar", salary: "44000" },
{ name: "Ranjith", salary: "88000" },
{ name: "Suman", salary: "95000" }
]
let newDevTeam = [];
//colculating month salaries expenditures
devTeam.forEach((person) => {
let newPerson = {...person, salary:parseInt(person.salary) + parseInt(person.salary * 10 / 100)}
newDevTeam.push(newPerson)
})
console.log(newDevTeam)
//==============================console=================================
//[{name: 'Nirav', salary: 55000}
//{name: 'Suraj', salary: 27500}
//{name: 'Amit', salary: 95700}
//{name: 'Ruthvik', salary: 25300}
//{name: 'Gayatri', salary: 19800}
//{name: 'Tarun', salary: 62700}
//{name: 'John', salary: 68200}
//{name: 'Michael', salary: 38500}
//{name: 'Sanjay', salary: 61600}
//{name: 'Manohar', salary: 48400}
//{name: 'Ranjith', salary: 96800}
//{name: 'Suman', salary: 104500}]
7. Team size has decreased by one member - pop()
After evaluating the team's performance, we have identified a non-performer impacting progress. We are reallocating them to another project for better alignment and efficiency.
pop()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//arranging rames in reverse-alphabet order
devTeam.pop();
console.log(devTeam)
//==============================console=================================
//['Nirav', 'Suraj', 'Amit', 'Ruthvik', 'Gayatri', 'Tarun', 'John', 'Michael', 'Sanjay', 'Manohar', 'Ranjith']
8. Replacing a new team member - splice()
Mr. Tarun has embarked on a new opportunity, and we appreciate his contributions. Moving forward, Mr. Varun will be taking over his role to ensure a seamless transition.
splice()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//Replacing Tarun(at Index 5) with Varun
devTeam.splice(5, 1, "Varun")
console.log(devTeam)
//==============================console=================================
//Previous output:-
//['Nirav', 'Suraj', 'Amit', 'Ruthvik', 'Gayatri', 'Tarun', 'John', 'Michael', 'Sanjay', 'Manohar', 'Ranjith', 'Suman']
//Current output:-
//['Nirav', 'Suraj', 'Amit', 'Ruthvik', 'Gayatri', 'Varun', 'John', 'Michael', 'Sanjay', 'Manohar', 'Ranjith', 'Suman']
9. Releasing two developers from the project - slice()
The product manager decided to release two developers from the current project. He plans to assign them to a new project next week. Until then, they will be on business wait.
slice()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//removing developers from index 1 and 2
console.log(devTeam.slice(1, 3))
//==============================console=================================
//['Suraj', 'Amit']
10. Employee data in text format - toString()
The HR Department needs employees’ data in string format.
toString()
//Create devTeam array
let devTeam = ["Nirav", "Suraj", "Amit", "Ruthvik", "Gayatri", "Tarun", "John", "Michael", "Sanjay", "Manohar", "Ranjith", "Suman"]
//removing developers from index 1 and 2
console.log(devTeam.toString())
//==============================console=================================
//Nirav,Suraj,Amit,Ruthvik,Gayatri,Tarun,John,Michael,Sanjay,Manohar,Ranjith,Suman