So this is what I am trying to solve:
class ViewRole {
name
description
constructor(name, description) {
this.name = name;
this.description = description;
}
}
class NewRole {
name;
description;
constructor(name, description) {
this.name = name;
this.description = description;
}
}
var armadilloRoles = [
new NewRole('Billing', 'armadillo.organization.billing'),
new NewRole('Doctor', 'armadillo.organization.doctor'),
new NewRole('Nurse Practitioner', 'armadillo.organization.nursePractitioner'),
new NewRole('Patient', 'armadillo.microurb.billing'),
new NewRole('Microurb admin', 'armadillo.organization.admin'),
new NewRole('Microurb admin', 'armadillo.organization.admin'),
new NewRole('Microurb billing', 'armadillo.organization.billing'),
new NewRole('Respiratory therapist', 'armadillo.microurb.respiratoryTherapist'),
new NewRole('Microurb commercial contact', 'armadillo.microurb.practiceGrowthDirector')
];
var viewRoles = [];
for (var i = 0; i < armadilloRoles.length; i++) {
const role = armadilloRoles[i];
const viewRoleDto = new ViewRole(role.name, role.description);
// if (viewRoleDto[i].description.startsWith('armadillo.organization.')) {
// viewRoles.push(viewRoleDto[i]);
// }
viewRoles.push(viewRole);
}
console.log(viewRoles);
I have tried a variety of ways of implementing an if conditional with a startsWith() method.
I want to return just the ones that have armadillo.organization. as the description.
A good way would be to use reduce like this:
const matches = armadilloRoles.reduce(
(prev, cur) =>
cur.description.startsWith("armadillo.organization") ? [...prev, cur] : prev,
[]
);