Announcement

Collapse
No announcement yet.

Passing Arrays To Functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing Arrays To Functions

    I have a new function that includes an array as one of its parameters. I created an array for testing using the following:

    var numArray = new Array(1,8,1,2,3,4,4,9,4,4,5,5,5,6,6,8,4,9);
    var newTemp = pk(numArray);
    .
    .
    .
    function pk(xArray) {
    .
    }

    The function works fine and returns the correct answer in test. Now, in my regular program, I have created an array using:

    if ( bInit == false ) {
    H1 = efsInternal("Calc_HV", xStdDev, nAnnual, nPer);
    H1 = getSeries(H1);
    bInit = true;
    }
    .
    .
    .
    var newTemp = pk(H1);

    Within my function, I can print out individual array elements as H1.getValue(...) and they are correct. The following statement in my function, which worked in test, now returns "undefined."

    var aCount = xArray.length;

    I did not make any changes to my function between testing and implementation, and all arrays have been defined globally. Since the H1 array was defined during initialization, do I need to pass that differently? I'm afraid that I'm not sure why this isn't working. Thanks for any help.

  • #2
    Re: Passing Arrays To Functions

    rauthur
    The efsInternal() function does not create an Array but a Series Object which does not have a length property [see the link to the corresponding article in the EFS KnowledgeBase]
    In your example H1 is a Series Object so if you want an array based on its values you will need to create one and populate it with the values retrieved from the series using the getValue() method of the Series Object
    Alex


    Originally posted by Rla1js
    I have a new function that includes an array as one of its parameters. I created an array for testing using the following:

    var numArray = new Array(1,8,1,2,3,4,4,9,4,4,5,5,5,6,6,8,4,9);
    var newTemp = pk(numArray);
    .
    .
    .
    function pk(xArray) {
    .
    }

    The function works fine and returns the correct answer in test. Now, in my regular program, I have created an array using:

    if ( bInit == false ) {
    H1 = efsInternal("Calc_HV", xStdDev, nAnnual, nPer);
    H1 = getSeries(H1);
    bInit = true;
    }
    .
    .
    .
    var newTemp = pk(H1);

    Within my function, I can print out individual array elements as H1.getValue(...) and they are correct. The following statement in my function, which worked in test, now returns "undefined."

    var aCount = xArray.length;

    I did not make any changes to my function between testing and implementation, and all arrays have been defined globally. Since the H1 array was defined during initialization, do I need to pass that differently? I'm afraid that I'm not sure why this isn't working. Thanks for any help.

    Comment


    • #3
      Well, that clears things up a bit. Thanks very much for your help.

      Comment


      • #4
        rauthur
        You are welcome
        Alex


        Originally posted by Rla1js
        Well, that clears things up a bit. Thanks very much for your help.

        Comment

        Working...
        X