Skip to content

Instantly share code, notes, and snippets.

@iamskok
Created June 19, 2020 00:23
Show Gist options
  • Save iamskok/f91268a2415368112f9d33bf76a6ee33 to your computer and use it in GitHub Desktop.
Save iamskok/f91268a2415368112f9d33bf76a6ee33 to your computer and use it in GitHub Desktop.
const employeeRegions = [
[
{
name: 'Mike',
age: 23,
title: 'engineer',
remote: false,
},
{
name: 'Liz',
age: 20,
title: 'engineer',
remote: true,
},
{
name: 'Chris',
age: 102,
title: 'president',
remote: true,
},
{
name: 'Chuloo',
age: 27,
title: 'manager',
remote: false,
},
],
[
{
name: 'Michelle',
age: 65,
title: 'engineer',
remote: true,
},
{
name: 'Sam',
age: 25,
title: 'manager',
remote: false,
},
{
name: 'Ivy',
age: 26,
title: 'engineer',
remote: false,
},
{
name: 'Nick',
age: 32,
title: 'engineer',
remote: true,
},
]
];
/**
* * Return an array of employees.
* * Do not include any employees who are remote.
* * Add a field "region" to each employee object. The region value should be
* ** the string "Region " together with the index of the group plus one
* ** "Region 1" (for index 0).
*
* @param {array[]} employeeRegions
* @returns {array}
*/
function transformGroups(employeeRegions) {
return employeeRegions.map((group, index) => {
return group.filter(employee => {
if (!employee.remote) {
employee.region = `Region ${index + 1}`;
return employee;
}
});
})
.flat();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment