Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PLEASE HELP, im i stupid or what, why i can't find any answer to my question on googl

    Let say i have many count as below

    A1_S1 = 0
    contiue to 100
    A100_S100 = 0

    which i want to count each of them got how much inside after the checker. Yes i do understand follow if/else or switch will help me done this, but can i know is there any faster way like "A1" and "S1" finder which is match will plus 1.
    Code:
    switch(Checker1){
    case A1: A0 = A1++;break;
    case A2: A0 = A2++;break;
    }
    
    switch(checker2){
    case S1: S0 = S1++;break;
    case S2: S0 = S2++;break;
    }
    
    var A0,S0;
    var Total = A0 + S0;
    if(Total == A1_S1){
    A1_S1++;
    }
    else if(Total == A2_S1){
    A2_S1++
    }
    else if(Total == A2_S2){
    A2_S2++
    }
    else if(Total == A0_S1){
    A0_S1++
    }
    Last edited by VIPStephan; 11-23-2012 at 09:35 AM. Reason: fixed code BB tag

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Every time you start to add literal digits to your variable names you'll have to consider using Arrays instead. Because this is exactly why they have been introduced into programming languages

    To initialize a two-dimensional array with zeroes you could do:
    Code:
    var myArray = [];
    for(i=0; i<100; i++) {
       myArray[i] = [];
       for(j=0; j<100; j++) {
          myArray[i][j] = 0;
       }
    }
    Now you can access the content easily like
    Code:
    alert(myArray[20][50]);
    // even using variables
    var myindex1 = 10;
    var myindex2 = 70;
    alert(myArray[myindex1][myindex2]);

  • #3
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank for your reply, first thing i wish to thank you for trying to help me out, and i have post this in few website also no one trying to help at all.

    For my code, what i wish to do is permutation count.

    like 1,2,3
    1,2,3
    1,2,3

    output to
    111 = 1
    112 = 1
    113 = 1
    121 = 1
    122 = 1
    123 = 1
    133 = 1
    211 = 1
    212 = 1
    213 = 1
    333 = 1
    and continue till all number is count and also store to the array which can check how many count after all

    code will check the input number and count how many outcome and show the results with how many outcome and each have how many after permutation count.

    Its hard to do?.

    Anyway thank you for help.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by HunterFai View Post
    Thank for your reply, first thing i wish to thank you for trying to help me out, and i have post this in few website also no one trying to help at all.

    For my code, what i wish to do is permutation count.

    like 1,2,3
    1,2,3
    1,2,3

    output to
    111 = 1
    112 = 1
    113 = 1
    121 = 1
    122 = 1
    123 = 1
    133 = 1
    211 = 1
    212 = 1
    213 = 1
    333 = 1
    and continue till all number is count and also store to the array which can check how many count after all

    code will check the input number and count how many outcome and show the results with how many outcome and each have how many after permutation count.

    Its hard to do?.

    Anyway thank you for help.

    Google is your friend! Examples:-

    http://scriptar.com/JavaScript/permute.html
    http://jsfiddle.net/MgmMg/6/

    The search feature of this forum is also your friend:-

    Need Permutation Script

    If you post in multiple forums you will find that you may not get an answer in any of them. People do not want to waste time answering a question when it has perhaps already been answered elsewhere.
    Last edited by Philip M; 11-27-2012 at 10:12 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •