Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:58:12+00:00 2026-06-09T22:58:12+00:00

I have a rather repetitive switch case statement and in my quest to learn

  • 0

I have a rather repetitive switch case statement and in my quest to learn the simplest way of doing things, I wanted to turn to SO and see if there is a more elegant solution to the following:

        switch(id)
        {
            case 'ib-02a':
                if(direction == 'left')
                    setHash('ib-02b');
                break;
            case 'ib-02b':
                if(direction == 'right')
                    setHash('ib-02a');
                if(direction == 'left')
                    setHash('ib-02c');
                break;
            case 'ib-02c':
                if(direction == 'right')
                    setHash('ib-02b');
                if(direction == 'left')
                    setHash('ib-02d');
                break;
            case 'ib-02d':
                if(direction == 'right')
                    setHash('ib-02c');
            break;

            case 'ib-03a':
                if(direction == 'left')
                    setHash('ib-03b');
                break;
            case 'ib-03b':
                if(direction == 'right')
                    setHash('ib-03a');
                if(direction == 'left')
                    setHash('ib-03c');
                break;
            case 'ib-03c':
                if(direction == 'right')
                    setHash('ib-03b');
                if(direction == 'left')
                    setHash('ib-03d');
                break;
            case 'ib-03d':
                if(direction == 'right')
                    setHash('ib-03c');
            break;

            case 'pb-05a':
                if(direction == 'left')
                    setHash('pb-05b');
                break;
            case 'pb-05b':
                if(direction == 'right')
                    setHash('pb-05a');
                if(direction == 'left')
                    setHash('pb-05c');
                break;
            case 'pb-05c':
                if(direction == 'right')
                    setHash('pb-05b');
                if(direction == 'left')
                    setHash('pb-05d');
                break;
            case 'pb-05d':
                if(direction == 'right')
                    setHash('pb-05c');
            break;
        }

I’m reading swipe events, and if the ID of the element I am swiping on matches either ib-02*, ib-03*, or pb-05*, I am calling a setHash function for the appropriate ID. If I’m swiping on *a, I swipe left to *b. If I’m swiping on *b, I swipe right to *a and left to *c. So on and so forth, always between *a and *d.

There must be a less repetitive way to do this, but I’m not sure exactly what the best approach is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:58:13+00:00Added an answer on June 9, 2026 at 10:58 pm

    How about mapping them to an object? Then just use the setHash with the retrieved value.

    var ids = {
        'pb-05c' : {
            left : 'pb-05d',
            right : 'pb-05b'
        }
        ...
    }
    
    function setHashes(id,direction){
        if(id && ids[id]){
            id = ids[id];
            if(direction && id[direction]){
                setHash(id[direction]);
            }
        }
    }
    

    It’s all retrieval and no condition evaluation, which can be good for performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather complicated (and very inefficient) way of getting utilisation from a
I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see
I'm doing a rather repetitive subtraction of values from column A and column B,
I have rather class using TcpClient that spins of a Thread doing while (!streamReader.EndOfStream)
I have rather large project that uses ICU regex classes. Basically it might run
Have a rather simple question. Does anyone knows if i can use jparallax both
I have some rather odd behavior in my D program that I've narrowed down
I have a rather large text corpus, of which I would like to check
I have a rather simple ListView row: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content
I have a rather complicated lookup for an option. It comes from a separate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.