SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple algorithm array elemets diference

    Hi, I need help to some simple algorithm

    I have a variable that I receive each 5seconds a value like 10 ..20 ..34..56..75 on websocket
    I need to store it in a array like value[n]

    only with n and n-1 this means the actual value received and last value received
    For example in above store only 34 and 56 and get its diference like 22 in a variable result

    I was thinking about push and pop in arrays

    Any help is welcome
    Regards

  2. #2
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SOLVED

    var data = [0];

    function diference(value){
    data.push(value);
    x=data.shift()-data[0]
    return (Math.abs(x));
    }


Tags for this Thread

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
  •