1
\$\begingroup\$

I'm looking into using my loop to combine and narrow down this piece of code into maybe a switch statement or other methods, how would I be able to achieve that? This is what I have so far which has worked for me but I also have other items[i].ApplicationType such as 'OneDrive', 'Teams', etc..

for(i = 0; i < items.length; i++)
{
    if(items[i].ComputerType == 'Windows' && items[i].RequestType == 'Single User' && items[i].ApplicationType == 'OneDrive')
    {
        ODwindows += 1;
    }
    else if(items[i].ComputerType == 'Windows' && items[i].RequestType == 'Single User' && items[i].ApplicationType == 'Teams')
    {
        Teamswindows += 1;
    }
    else if(items[i].ComputerType == 'Mac' && items[i].RequestType == 'Single User' && items[i].ApplicationType == 'OneDrive')
    {
        ODmac += 1;
    }
    else if(items[i].ComputerType == 'Mac' && items[i].RequestType == 'Single User' && items[i].ApplicationType == 'Teams')
    {
        Teamsmac += 1;
    }
    else if(items[i].ComputerType == 'Both' && items[i].RequestType == 'Team' && items[i].ApplicationType == 'OneDrive')
    {
        ODboth += 1;
    }
    else if(items[i].ComputerType == 'Both' && items[i].RequestType == 'Team' && items[i].ApplicationType == 'Teams')
    {
        Teamsboth += 1;
    }
}
\$\endgroup\$

closed as off-topic by 200_success, Toby Speight, yuri, Sᴀᴍ Onᴇᴌᴀ, IEatBagels Jun 4 at 19:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – 200_success, Toby Speight, yuri, Sᴀᴍ Onᴇᴌᴀ, IEatBagels
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    \$\begingroup\$ Please provide more context: what are the inputs, what do you do with the outputs, and what does this code accomplish? See How to Ask. \$\endgroup\$ – 200_success Jun 4 at 14:42
  • \$\begingroup\$ Welcome to Code Review! What task does this code accomplish? Please tell us, and also make that the title of the question via edit. Maybe you missed the placeholder on the title element: "State the task that your code accomplishes. Make your title distinctive.". Also from How to Ask: "State what your code does in your title, not your main concerns about it.". \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Jun 4 at 15:22

Browse other questions tagged or ask your own question.