getEmployeesOver
Random YouTube challenge
by trentHarlem
HTML
<p>
Rando YouTube challenge
</p>
<p>
Return highest paid employees
</p>
<p>
Deliver a function that takes two arguments, 1, a 'list' parameter ( an Object/Array of Strings ) and filter that list by the 2,'salary' parameter ( a Number )
</p>
JavaScript
// example data
/* function filterSort(Object,Number) {
filter
} */
// make a list of 10 example 'employees' each with a unique 'name' and a 'salary' (range between 45,000 and 139,000).
const employees = [{
name: "John",
salary: 45000
},
{
name: "Jane",
salary: 55000
},
{
name: "Jim",
salary: 65000
},
{
name: "Jill",
salary: 75000
},
{
name: "Jack",
salary: 85000
},
{
name: "Joan",
salary: 95000
},
{
name: "Johan",
salary: 105000
},
{
name: "Jenna",
salary: 115000
},
{
name: "Jami",
salary: 125000
},
{
name: "Jeniffer",
salary: 135000
},
{
name: 'Jacob',
salary: 115000
},
{
name: 'Jami',
salary: 125000
},
{
name: 'Jeniffer',
salary: 69000
},
{
name: 'Jason',
salary: 109000
},
{
name: 'Joseph',
salary: 119000
},
{
name: 'Jolene',
salary: 129000
},
{
name: 'Judy',
salary: 139000
},
{
name: 'Jesse',
salary: 149000
},
{
name: 'Jared',
salary: 159000
},
{
name: 'Jorge',
salary: 169000
},
{
name: 'Javier',
salary: 79000
},
{
name: 'Juan',
salary: 48000
},
];
console.log(employees.length)
// create a function that take 2 params, list and salary. it returns a list (array with descending order) containing the employees names with salaries over the amount in the salary argument.
function getEmployeesOver(list, salary) {
// create a new array to hold the employees that meet the criteria
const employeesOver = [];
const filter = salary;
console.log(salary)
// loop through the list of employees
for (let i = 0; i < list.length; i++) {
// if the salary of the current employee is greater than the salary argument
if (list[i].salary > salary) {
// add the name of the employee to the employeesOver array
employeesOver.push(list[i].name);
}
}
return employeesOver
//return...