[javascript-dev] Re: js question from a newbie
Greg
peripatitis at gmail.com
Mon Mar 31 15:08:57 MDT 2008
- Previous message: [javascript-dev] Re: js question from a newbie
- Next message: [javascript-dev] Re: "immediate" crash in overdrive (Windows XP)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Sorry for the many questions but i am new to programming generally as well as specifically in javascript .
This is a new problem i am came up with :
I am having an input list sent to a specific function
where i save it as an array .
The array is declared as a variable within the function , however it seems that i can access it through other functions as well.
Is this normal behaviour ?
I am wondering since this is part of a bigger program , what will happen if i have two arrays with same name .
here is thecode :
editfontsize = 16 ;
// trying to create a function that takes an input list and create a new array taking into account the specified weights
var z = new Array() ; // the array where i copy the a value from an input list
var x = new Array() ; // the array where i copy the b value form an input list
var v = new Array(); // the array where i copy the weighting value from an input list
function sortit() // this is where i sort the input array into three distinct arrays
{
count1 = count2 = count3 = 0 ; // a local counter used to set the elements of the three arrays
v.length = x.length = z.length = (inputweights.length / 3) // here i set the length of the three lists (perhaps not needed)
var t = inputweights.slice(); // copy the initial list
var i = 0;
{for ( i = 0 ; i < t.length ; i ++)
if (( i % 3) == 0)
{z[count1] = t[i]
count1++ ;}
else
{if ((i % 3) == 1)
{x[count2] = t[i]
count2++ ;}
else
{v[count3] = t[i]
count3++ ;}}}
post();
post("my a values are " , z) ;
post() ;
post(" my b values are " ,x) ;
post();
post("my weigth values are " , v) ;
}
function bang ()
{ sortit()}
function weights(a) // saves the input to the weight function into an array
{
var inputweights = new Array ;
post() ;
post("the list contains",arguments.length,
"elements");
if (( arguments.length % 3) != 0) // checks to see whether we have the correct number of arguments ( a b weight)
{post();
post(" wrong number of arguments in the list ") ;
post() ;}
else
{for ( i = 0 ; i < arguments.length ; i++)
inputweights[i] = arguments[i];
post();
post(inputweights) ;
post() ;}
}
- Previous message: [javascript-dev] Re: js question from a newbie
- Next message: [javascript-dev] Re: "immediate" crash in overdrive (Windows XP)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
