What is the best solution to simplify this condition statement?
Should I use switch statement?
function handleUserRole(title) {
if (title === 'mr') {
// logic
} else if (title === 'ms') {
// logic
} else if (title === 'name') {
// logic
if (/* some condition */) {
// logic
} else {
// logic
}
} else if (title === 'surname') {
// Guest-specific logic
} else if (title === 'member') {
// logic
if (/* some condition */) {
// logic
} else {
// logic
}
} else if (title === 'test') {
// logic
} else if (title === 'blank') {
// logic
} else {
// logic
}
}
I tried switch statement for it but not sure if this is the best solution.