SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Location
    delhi
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Adding The Last Same repetitive Values Of Output



    If The output of a var R is :
    0
    21
    23
    45
    34
    55
    6
    6
    45
    67
    32
    32
    55
    8
    8
    8
    93
    25
    83
    1
    4
    76
    53
    64

    Can we somehow Add The Last Same repetitive Values Of R like here in the example

    6
    6

    and

    8
    8
    8

    are the same values of R which are repetitive.
    can we trace some message when ever this happens ?
    and can we add them to get their total like
    R_Sum = 8+8+8
    R_Sum = 24

    ANY iDEA ??

    please see the my Fla
    Attached Files Attached Files

  2. #2
    SitePoint Guru krityx's Avatar
    Join Date
    Jan 2006
    Location
    Around
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here you go

    Code Actionscript:
    var w:Array = new Array();
    var v:Array = new Array();
    var s:Number = 0;
    var c:Number = 1;
    var sum:Number = new Number();
    var f:Boolean = false;
     
    for (i=1; i<=10; i++) {
    R = random(5);
    v.push(R);
    }
    trace("v = " + v);
     
    j=v.length ;
    while(j != 0)
    {
        w.push(v[j-1]);
        j--;
    }
    trace("v backwards = " + w);
     
    for(k=0; k<=w.length; k++)
    {
     
        if(w[k] == w[k+1]){
            e = w[k];
            c++;
            f=true;
        }
        if(w[k] != w[k+1] && e != undefined){
            break;
        }
     
    }
    sum = e*c ;
    trace("the last repeated number is " + e);
     
    trace("sum = " + sum);
     
    stop();



Bookmarks

Posting Permissions

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