[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Layered object

JT

5/21/2016 5:41:00 PM

I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.

Right now the storing structure look like this and i set fontcolor and rectangle color as i print out the grid.

However i would like to store multiple func and rcolors within same object?
Thus make func and rcolor the multidimensional part of the array.

I am totally clueless for how both initiate and update such an object in javascript. I have managed to do it for numbers but i never initiated the object it was somehow forked in as i updated the object. And i really did not understand how it really worked. So if someone could show me howto make this array of integers to holld multiple functions and rectangles for each arr[i] it would be great.

function arraysize()
{

for ( i = - scope; i <= scope; i ++ )
{
arr[i] =
{
count : i,
func : '',
fcolor : 'black',
rheight : 100,
rwidth : 100,
rcolor : 'white',
prime : true,
formula : 0,
sigma : 0,
}
}
}
38 Answers

Aleksandro

5/21/2016 11:42:00 PM

0

On 21/05/16 13:41, jonas.thornvall@gmail.com wrote:
> I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
>
> Right now the storing structure look like this and i set fontcolor and rectangle color as i print out the grid.
>
> However i would like to store multiple func and rcolors within same object?
> Thus make func and rcolor the multidimensional part of the array.
>
> I am totally clueless for how both initiate and update such an object in javascript. I have managed to do it for numbers but i never initiated the object it was somehow forked in as i updated the object. And i really did not understand how it really worked. So if someone could show me howto make this array of integers to holld multiple functions and rectangles for each arr[i] it would be great.
>
> function arraysize()
> {
>
> for ( i = - scope; i <= scope; i ++ )
> {
> arr[i] =
> {
> count : i,
> func : '',
> fcolor : 'black',
> rheight : 100,
> rwidth : 100,
> rcolor : 'white',
> prime : true,
> formula : 0,
> sigma : 0,
> }
> }
> }
>

Sorry but I am drunk lol I wall think for an ann-er in the morning lololol

JT

5/22/2016 6:43:00 AM

0

Den söndag 22 maj 2016 kl. 01:41:58 UTC+2 skrev Aleksandro:
> On 21/05/16 13:41, jonas.thornvall@gmail.com wrote:
> > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> >
> > Right now the storing structure look like this and i set fontcolor and rectangle color as i print out the grid.
> >
> > However i would like to store multiple func and rcolors within same object?
> > Thus make func and rcolor the multidimensional part of the array.
> >
> > I am totally clueless for how both initiate and update such an object in javascript. I have managed to do it for numbers but i never initiated the object it was somehow forked in as i updated the object. And i really did not understand how it really worked. So if someone could show me howto make this array of integers to holld multiple functions and rectangles for each arr[i] it would be great.
> >
> > function arraysize()
> > {
> >
> > for ( i = - scope; i <= scope; i ++ )
> > {
> > arr[i] =
> > {
> > count : i,
> > func : '',
> > fcolor : 'black',
> > rheight : 100,
> > rwidth : 100,
> > rcolor : 'white',
> > prime : true,
> > formula : 0,
> > sigma : 0,
> > }
> > }
> > }
> >
>
> Sorry but I am drunk lol I wall think for an ann-er in the morning lololol

Lets hope you sobered up...
var x = new Array(10);
for (var i = 0; i < 10; i++) {
x[i] = new Array(20);
}
x[5][12] = 3.0;

How does this relate to my example array above?
I do not know how many occurences there will be, and it is only the func and rcolor property of the object that will be multidimensional.

for ( i = - scope; i <= scope; i ++ )
{

arr[i] =
{
count : i,
func : '',
fcolor : 'black',
rheight : 100,
rwidth : 100,
rcolor : 'white',
prime : true,
formula : 0,
sigma : 0,
}
arr[i] = new Array(20);//??????????
}
}

JT

5/22/2016 10:51:00 AM

0

Den söndag 22 maj 2016 kl. 08:42:41 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 22 maj 2016 kl. 01:41:58 UTC+2 skrev Aleksandro:
> > On 21/05/16 13:41, jonas.thornvall@gmail.com wrote:
> > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> > >
> > > Right now the storing structure look like this and i set fontcolor and rectangle color as i print out the grid.
> > >
> > > However i would like to store multiple func and rcolors within same object?
> > > Thus make func and rcolor the multidimensional part of the array.
> > >
> > > I am totally clueless for how both initiate and update such an object in javascript. I have managed to do it for numbers but i never initiated the object it was somehow forked in as i updated the object. And i really did not understand how it really worked. So if someone could show me howto make this array of integers to holld multiple functions and rectangles for each arr[i] it would be great.
> > >
> > > function arraysize()
> > > {
> > >
> > > for ( i = - scope; i <= scope; i ++ )
> > > {
> > > arr[i] =
> > > {
> > > count : i,
> > > func : '',
> > > fcolor : 'black',
> > > rheight : 100,
> > > rwidth : 100,
> > > rcolor : 'white',
> > > prime : true,
> > > formula : 0,
> > > sigma : 0,
> > > }
> > > }
> > > }
> > >
> >
> > Sorry but I am drunk lol I wall think for an ann-er in the morning lololol
>
> Lets hope you sobered up...
> var x = new Array(10);
> for (var i = 0; i < 10; i++) {
> x[i] = new Array(20);
> }
> x[5][12] = 3.0;
>
> How does this relate to my example array above?
> I do not know how many occurences there will be, and it is only the func and rcolor property of the object that will be multidimensional.
>
> for ( i = - scope; i <= scope; i ++ )
> {
>
> arr[i] =
> {
> count : i,
> func : '',
> fcolor : 'black',
> rheight : 100,
> rwidth : 100,
> rcolor : 'white',
> prime : true,
> formula : 0,
> sigma : 0,
> }
> arr[i] = new Array(20);//??????????
> }
> }

If i let out 20 above, arr[i] = new Array(); will the subarray dynamically assign memory as i pass new properties?

So to update the object i use arr[x][y].func="mystring" or arr[x][y].rcolor="green".

Is there space allocated for the rest of the attributes/properties of the object?

Does the object creation and the update seem right?



Michael Haufe (\"TNO\")

5/22/2016 4:03:00 PM

0

On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.

Don't. It's going to be slower.

JT

5/22/2016 10:00:00 PM

0

Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
>
> Don't. It's going to be slower.

Well just storing them within the array can hardly slow it down or?

Michael Haufe (\"TNO\")

5/22/2016 10:58:00 PM

0

On Sunday, May 22, 2016 at 4:59:50 PM UTC-5, jonas.t...@gmail.com wrote:
> Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> > On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> >
> > Don't. It's going to be slower.
>
> Well just storing them within the array can hardly slow it down or?

Memoization isn't free and your approach would be even less so. I've written a little about this topic in the past:

<https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-ju...

JT

5/23/2016 5:46:00 AM

0

Den måndag 23 maj 2016 kl. 00:57:57 UTC+2 skrev Michael Haufe (TNO):
> On Sunday, May 22, 2016 at 4:59:50 PM UTC-5, jonas.t...@gmail.com wrote:
> > Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> > > On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> > >
> > > Don't. It's going to be slower.
> >
> > Well just storing them within the array can hardly slow it down or?
>
> Memoization isn't free and your approach would be even less so. I've written a little about this topic in the past:
>
> <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-ju...

Beside for the last example, what is really the benefit of the recursive examples compared to the iterative?

For me that is not used to recursive calls the iterative naive approach using for and while is much easier to read and understand.

What is the main benefit with recursive calls, speed?

JT

5/23/2016 6:05:00 AM

0

Den måndag 23 maj 2016 kl. 00:57:57 UTC+2 skrev Michael Haufe (TNO):
> On Sunday, May 22, 2016 at 4:59:50 PM UTC-5, jonas.t...@gmail.com wrote:
> > Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> > > On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> > >
> > > Don't. It's going to be slower.
> >
> > Well just storing them within the array can hardly slow it down or?
>
> Memoization isn't free and your approach would be even less so. I've written a little about this topic in the past:
>
> <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-ju...

Do you have any suggestion, or do you just say it is not wise to make a deeper multidimensional storage structure?

I think the script could benefit from using a layered structure for the expression. For those integers that get multiple occurences i just put a border around no need to draw them out.

And then you could use an optional event handler on mouse over and on mouse click to zoom in and scroll through the occurences/expressions.

JT

5/23/2016 6:09:00 AM

0

Den måndag 23 maj 2016 kl. 00:57:57 UTC+2 skrev Michael Haufe (TNO):
> On Sunday, May 22, 2016 at 4:59:50 PM UTC-5, jonas.t...@gmail.com wrote:
> > Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> > > On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> > >
> > > Don't. It's going to be slower.
> >
> > Well just storing them within the array can hardly slow it down or?
>
> Memoization isn't free and your approach would be even less so. I've written a little about this topic in the past:
>
> <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-ju...

I like your writing style better than the recursive programming, very clear and concise. :)

JT

5/23/2016 3:32:00 PM

0

Den måndag 23 maj 2016 kl. 00:57:57 UTC+2 skrev Michael Haufe (TNO):
> On Sunday, May 22, 2016 at 4:59:50 PM UTC-5, jonas.t...@gmail.com wrote:
> > Den söndag 22 maj 2016 kl. 18:03:24 UTC+2 skrev Michael Haufe (TNO):
> > > On Saturday, May 21, 2016 at 12:41:36 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > I have an object storing integers, many formulas may of course generate the same integer. And for some expressions for example on form a*x^j i would like to store each occurence. Now all my numbers are printed out in a square grid.
> > >
> > > Don't. It's going to be slower.
> >
> > Well just storing them within the array can hardly slow it down or?
>
> Memoization isn't free and your approach would be even less so. I've written a little about this topic in the past:
>
> <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-ju...

For even greater justice, but a tad slower using base 10 but faster and bigger using bigger base.

<script language="Javascript">

/*ADD TWO VARIABLES USING CHOSEN BASE*/
function naiveAdd(base, arrOne, arrTwo)
{
addOne=arrOne.slice();
addTwo=arrTwo.slice();
abigArr = addOne.length;
asmallArr = addTwo.length;
addResult = [];
remainder = 0;
for (i = 0; i < asmallArr; i ++ )
{

addOne[i] = addOne[i] + addTwo[i] + remainder;
if (addOne[i] >= base)
{

addOne[i] = addOne[i] - base;
remainder = 1;

}
else
{
remainder = 0;
}
}
// If strings of equal length but there is a remainder;
while (remainder == 1 && addOne[i]==(base-1))
{
addOne[i] = 0;
i++;
}
if (remainder == 1) {if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;}
return addOne;
}

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
function lessThan(A, B)
{
var AA = A.length;
var BB = B.length;
if(AA > BB) return false;
if(AA < BB) return true;
// AA = BB, compare indexes from biggest to smallest.
for(i = AA - 1; i >= 0; i -- )
{
if(A[i] < B[i]) return true;
if(A[i] > B[i]) return false;
}
return false;
}

/* ORDER THE ARRAYS SO THE BIGGER IS PASSED AS FIRST ARGUMENT*/
function orderArrayAdd(Abase, A, B)
{
return lessThan(A, B) ? counterArr = naiveAdd(Abase, B, A) : counterArr = naiveAdd(Abase, A, B);
}

/* GET VALUES FROM INPUT*/
function fetchValues(){
base=document.eval.FBASE.value;
myeval = document.eval.expression.value;
lucasStart = document.eval.start.value;
lStart=parseInt(lucasStart)
lucasScope = document.eval.scope.value;
lScope=parseInt(lucasScope)
}

/* PARSE VALUES FROM INPUT */
function parseToInt(){
if (result = myeval.indexOf("+") != - 1)
{
opArr = myeval.split("+");
operation = "+";
}
arrOne = opArr[0].split("").map(Number).reverse();
arrTwo = opArr[1].split("").map(Number).reverse();
}


function main(){
document.eval.result.value="";
document.eval.timing.value="";
evalStr="";
var out=[];counter=1;
fetchValues();
base=parseInt(base);
parseToInt();
flip=0;
/* TIMER START */
var start = new Date().getTime();
lEnd=lStart+lScope;

while(counter<=lEnd){
out=orderArrayAdd(base,arrOne,arrTwo);
arrOne=arrTwo.slice();
arrTwo=out.slice();
if (counter>=lStart && counter<lEnd) {fib=out.slice();evalStr+=counter+"th"+" "+fib.reverse().join(',')+"\n";}
counter++;
}
/* TIMER END */
var end = new Date().getTime();
var time = end - start;
document.eval.result.value+=evalStr;
document.eval.timing.value+=time;
} </script>

<html><body onLoad="main()";>
<H1>FIBONACCI AND OTHER SERIES</H1>
<form name="eval" onsubmit="main(); return false;">
CHOSE BASE <input type="text" name="FBASE" value="4503599627370495" size="20"><P>
<input type="submit" value="Generate"><input type="text" name="timing" value="" size="4"> ms<br>
Start print x'th number in Serie<input type="text" name="start" value="100000" size="9"> How many follwing in Serie -><input type="text" name="scope" value="1" size="9"><br>
Generate Serie expansons using startvalues<input type="text" name="expression" value="1+0" size="10"><br>
Result <textarea name="result" cols="100" rows="30"></textarea><br>


</form>
</body></html>