Skip navigation
Currently Being Moderated

best way to check info that's in different sequence? Recognise ABC, CBA, ACBas correct

Sep 7, 2012 11:21 PM

I'll probably have my info push into an array. but I do not want to check each sequence one by one as it's gonna take a long process. is there a better way to solve this? Thanks

 
Replies
  • Currently Being Moderated
    Sep 8, 2012 4:27 AM   in reply to WitchXHunter

    It is not clear what you will have pushed into an array, but you can use the indexOf() method of the Array or the String class to check if they contain certain characters/elements.

     

    if(String("ABC").indexOf("C") > -1)  // C is in the string

     

    if(String("ABC").indexOf("A") > -1)  // A is in the string

     

    if(String("ABC").indexOf("B") > -1)  // B is in the string

     

    So you can just build a loop that goes thru your other String (CAB) and test each character using one line of the the code above with the indexOf argument being a variable

     

    Another option would be to sort both sets you want to compare in arrays and then see if they are equal one for one.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2012 7:36 AM   in reply to WitchXHunter

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points