I'm trying to run a script with 4 inputs, one is a Users name and the other three are lists of users labeled Junior, Mid, Senior. I want to return Junior, Mid or Senior depending on which list the User is in, the user will always be in one of the lists. When I run tests where I search for a user within the Junior list the output is 'Name not found in any list'.
I will attach my script code below; the logic seems right however it does not find the user in the lists.
Script:
function findUserList(User, SeniorList, MidList, JuniorList) {
// Check if the inputs are strings and split them into arrays; if not, use them as they are
let seniorArray = Array.isArray(SeniorList) ? SeniorList : SeniorList.toString().split(", ");
let midArray = Array.isArray(MidList) ? MidList : MidList.toString().split(", ");
let juniorArray = Array.isArray(JuniorList) ? JuniorList : JuniorList.toString().split(", ");
// Iterate through each list to find the User
if (seniorArray.includes(User)) {
return 'Senior';
} else if (midArray.includes(User)) {
return 'Mid';
} else if (juniorArray.includes(User)) {
return 'Junior';
} else {
return 'Name not found in any list';
}
}
let inputVar = input.config();
let user = inputVar.User;
let seniorlist = inputVar.SeniorList;
let midList = inputVar.MidList;
let juniorList = inputVar.JuniorList;
let listName = findUserList(user, seniorlist, midList, juniorList);
console.log(listName);