Javascript issue: array.push

Thread Tools Search this Thread
Top Forums Programming Javascript issue: array.push
# 1  
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:
<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;

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:

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:

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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 9... (1 Reply)
Discussion started by: popeye
1 Replies

9. 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

10. 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
Login or Register to Ask a Question

Featured Tech Videos