Sponsored Content
Full Discussion: Javascript issue: array.push
Top Forums Programming Javascript issue: array.push Post 302758619 by figaro on Sunday 20th of January 2013 09:21:16 AM
Old 01-20-2013
Code Javascript issue: array.push

I have a code snippet here that is supposed to vary values of certain parameter values:
Code:
<script type="text/javascript">
// dynamic array of which its ultimate size is unknown
// an array of arrays, each consisting of one variation
var variations = []; 

// parameters of how to create a variation
// data structure: initial parameter value, range size, step size
var parameters = [];
parameters[0] = [14, 2, 1];
parameters[1] = [25, 2, 1];
document.write("parameters: " + parameters + "<br>");
for (var j in parameters) document.write("parameters[" + j + "]: " + parameters[j] + "<br>");

// main loop
for (var k in parameters) create_variation(variations, parameters, k);
document.write("variations: " + variations + "<br>");

// create a variation and add it to variations
function create_variation(arr, params, k) {
  var a = [];
  
  // create initial variation
  for (var i = 0; i < params.length; i++) a[i] = params[i][0];
  document.write("initial variation: " + a + "<br>");
  document.write("parameters: " + params[k] + "<br>");

  // create variations
  for (i = params[k][0] - params[k][1]; i < params[k][0] + params[k][1] + 1; i += params[k][2]) { 
    a[k] = i;      // vary parameter value in location k only, leaving the rest intact
    arr.push(a);   // push it onto the variations array
    document.write("k: " + k + "<br>" + "a: " + a + "<br>");
  }
  return arr;
}
</script>

The array parameters is the mapping with which the value is allowed to vary. So in the first case, the value is 14, allowed to vary with value 2 in steps of 1, which by itself would yield: 12, 13, 14, 15, 16.
The variation is with all other values in the parameters array as well. So ultimately there should be an array variations as follows:
Code:
[12,25],[13,25],[14,25],[15,25],[16,25]
[12,23],[13,23],[14,23],[15,23],[16,23]
[12,24],[13,24],[14,24],[15,24],[16,24]
[12,25],[13,25],[14,25],[15,25],[16,25]
[12,26],[13,26],[14,26],[15,26],[16,26]
[12,27],[13,27],[14,27],[15,27],[16,27]

Note that I am not worried about duplicates right now: row 1 and 4 are identical.
I don't understand however why the results returned only yield the following:
Code:
[16,25],[16,25],[16,25],[16,25],[16,25],
[14,27],[14,27],[14,27],[14,27],[14,27]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamic Array Issue

Could one of you, please, provide some input regarding my problem below and it is as follows: I have 2 files that I need to make sure are identical before processing: First, I sort both files Second, I do a diff file1 file2 > File 3 This provides me with the difference. Now, I need to... (6 Replies)
Discussion started by: ddedic
6 Replies

2. Solaris

V880 and T3 array issue

We're trying to install a third T3 array onto our V880. The other two T3's are connected to a qlogic fibre card. We can see this connection fine when we do a luxadm probe -p command. The full device paths are shown etc. ie: the first T3's logical name is c2t1d0 and the second one is c3t1d0. ... (3 Replies)
Discussion started by: mjl927
3 Replies

3. Shell Programming and Scripting

Perl - if conditions is meet, push the last field of $_ into an array

I am using a seed file shown below to separate cisco devices by ios/os type. I want to bunch all the devices based on ios/os version. Once I find a match, I only want to push the ip address into the appropriate array. Example of seedfile 8 host1 (C3500XL-C3H2S-M) 11.0(5)WC17 10.1.44.21 9... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

PERL, push to hash of array problem

$key = "a"; $value = "hello"; %myhash = {} ; push @{ myHash{$key} }, $hello; print $myHash{$key}."\n"; this script prints "hello" but has following error message. Reference found where even-sized list expected at ./test line 5. can any one help me to fix this problem?? (3 Replies)
Discussion started by: bonosungho
3 Replies

5. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

6. Shell Programming and Scripting

Scripting array issue

Hi guys, I'm a scripting noob in need of some help :) I am creating a script that checks the filesystems and will alert based upon if the percent full is greater than the threshold set. The problem that I am having is that when I set the 'filesystem' variable, all of the output is treated as... (12 Replies)
Discussion started by: tank126
12 Replies

7. Shell Programming and Scripting

Array usage issue with AWk

Hi friends, I m trying to write small script in awk alone. And I have tried below logic for one of my automation - taking the first column of the file in array and will read in for loop for each time when i grep the array value in the same file I should get complete output whichever is matching... (3 Replies)
Discussion started by: Shahul
3 Replies

8. Shell Programming and Scripting

Issue with array in shell

So i have used arrays for a while now but I just notice in one of my arrays when using an array with 9+ items in it that after running a for loop on the array it was replacing the first array with what ever was last and I cant figure out why. Here is my code. #!/bin/bash vm=( 0 1 2 3 4 5 6... (3 Replies)
Discussion started by: snptuning
3 Replies

9. Shell Programming and Scripting

Array Issue In Bash

Hi, I have the following code which is giving error mentioned below. Please can you support on this. Also suggest how can we access all the items against single vasservicename in circlename array,i.e, vasservicename say MTSTV will be available to all circles which are mentioned in the array... (2 Replies)
Discussion started by: siramitsharma
2 Replies

10. Shell Programming and Scripting

awk array next issue

Hi, Here's an example of what I my issue, a file list.txt, which looks like: a b c d e I have been trying to use the following code to simply print the list using awk and next: awk 'FNR==NR{a=$1;next}{print a}' list.txt this give no output, even though I would expect it to type out... (5 Replies)
Discussion started by: hexy
5 Replies
GLGETCOLORTABLEPARAMETER(3G)											      GLGETCOLORTABLEPARAMETER(3G)

NAME
glGetColorTableParameterfv, glGetColorTableParameteriv - get color lookup table parameters C SPECIFICATION
void glGetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) void glGetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) PARAMETERS
target The target color table. Must be GL_COLOR_TABLE, GL_POST_CONVOLUTION_COLOR_TABLE, GL_POST_COLOR_MATRIX_COLOR_TABLE, GL_PROXY_COLOR_TABLE, GL_PROXY_POST_CONVOLUTION_COLOR_TABLE, GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE. pname The symbolic name of a color lookup table parameter. Must be one of GL_COLOR_TABLE_BIAS, GL_COLOR_TABLE_SCALE, GL_COLOR_TABLE_FORMAT, GL_COLOR_TABLE_WIDTH, GL_COLOR_TABLE_RED_SIZE, GL_COLOR_TABLE_GREEN_SIZE, GL_COLOR_TABLE_BLUE_SIZE, GL_COLOR_TABLE_ALPHA_SIZE, GL_COLOR_TABLE_LUMINANCE_SIZE, or GL_COLOR_TABLE_INTENSITY_SIZE. params A pointer to an array where the values of the parameter will be stored. DESCRIPTION
Returns parameters specific to color table target. When pname is set to GL_COLOR_TABLE_SCALE or GL_COLOR_TABLE_BIAS, glGetColorTableParameter returns the color table scale or bias parameters for the table specified by target. For these queries, target must be set to GL_COLOR_TABLE, GL_POST_CONVOLUTION_COLOR_TABLE, or GL_POST_COLOR_MATRIX_COLOR_TABLE and params points to an array of four elements, which receive the scale or bias factors for red, green, blue, and alpha, in that order. glGetColorTableParameter can also be used to retrieve the and size parameters for a color table. For these queries, set target to either the color table target or the proxy color table target. The and size parameters are set by glColorTable. The following table lists the and size parameters that may be queried. For each symbolic constant listed below for pname, params must point to an array of the given length, and receive the values indicated. ------------------------------------------------------------------- Parameter N Meaning ------------------------------------------------------------------- GL_COLOR_TABLE_FORMAT 1 Internal (e.g. GL_RGBA) GL_COLOR_TABLE_WIDTH 1 Number of elements in table GL_COLOR_TABLE_RED_SIZE 1 Size of red component, in bits GL_COLOR_TABLE_GREEN_SIZE 1 Size of green component GL_COLOR_TABLE_BLUE_SIZE 1 Size of blue component GL_COLOR_TABLE_ALPHA_SIZE 1 Size of alpha component GL_COLOR_TABLE_LUMINANCE_SIZE 1 Size of luminance component GL_COLOR_TABLE_INTENSITY_SIZE 1 Size of intensity component ------------------------------------------------------------------- NOTES
glGetColorTableParameter is present only if GL_ARB_imaging is returned when glGetString is called with an argument of GL_EXTENSIONS. ERRORS
GL_INVALID_ENUM is generated if target or pname is not an acceptable value. GL_INVALID_OPERATION is generated if glGetColorTableParameter is executed between the execution of glBegin and the corresponding execution of glEnd. SEE ALSO
glColorTable(3G), glTexParameter(3G), glColorTableParameter(3G) GLGETCOLORTABLEPARAMETER(3G)
All times are GMT -4. The time now is 09:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy