Is there a more efficient way to achieve the same outcome?
Brief Description:
routes = [
{ name: 'vehicle', activated: true},
{ name: 'userassignment', activated: true},
{ name: 'relations', activated: true},
{ name: 'journeys', activated: true},
{ name: 'expenses', activated: true}
];
Your Task - Develop a function that can perform the following actions on the array above:
- Set all members' property "activated" to false
- Choose one specific member and set its "activated" property to true based on its 'name'
- If the chosen member is 'journeys' or 'expenses', set them to true AND also set the 'relations' member to true
I have implemented the following code to accomplish this task, but my senior wants a smarter solution.
highlightActiveRoute(array: any[], chosen: string) {
array.forEach(element => {
element.activated = false;
if (element.name === chosen) {
element.activated = true;
if (element.name === 'journeys' || element.name === 'expenses') {
this.routes[2].activated = true;
}
}
});
}
I'm unsure if I can make it smarter, but perhaps you can provide some inspiration. Thank you!