473,378 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

special array cycles

Array so: for every value 1st column correspond one in 2nd
2 25
25 27
27 60
4 50
27 61

be able to write this
2 25,27,60,61
4 50

this steps:
-2nd isn't in right then rewrite in 1st column with its value (25)
-the 25 is also in 2nd column, then its value 27 go near 25
.....

some particular code?
Aug 24 '06 #1
8 2575
On 8/24/2006 12:10 PM, padew wrote:
Array so: for every value 1st column correspond one in 2nd
2 25
25 27
27 60
4 50
27 61

be able to write this
2 25,27,60,61
4 50

this steps:
-2nd isn't in right then rewrite in 1st column with its value (25)
-the 25 is also in 2nd column, then its value 27 go near 25
....

some particular code?
There are probably simpler ways to do this, but here's one:

a=[[2,25],[25,27],[27,60],[4,50],[27,61]];

function foo (x)
{
var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (z[y] == null)
z[y] = [x[i][1]];
else
z[y].push (x[i][1]);
}

return z;
}

As you can see, I'm presuming that you meant to truncate 1st col
numbers 9 to the tens (and beyond) digits.
--
_________________________________________
Bob Smith -- bs****@sudleydeplacespam.com

To reply to me directly, delete "despam".
Aug 24 '06 #2
I have tested (see code below);
but I have some undefinid value.
Now I have:
undefined
undefined
25,27,60,61
undefined
50

anyway the result seem ok;

undefined is my bad code (can you correct?)
but I would like to have the first values 2 and 4
2 25,27,60,61
4 50
-------------
and if I use this
x=[[2,3],[3,4],[1,10],[16,12],[1,15],[2,16],[4,18],[16,19],[1,20],[6,23],[10,25],[10,26],[19,30],[25,32]];

what I must to change in the code?
I think 9 and 10, but change with 27 e 28?
I have now 14 element [ ] in X; is so?
for tests:

function foo ()
{ var var_box=document.frm.my_box;
var var_c=0;

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];

var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (z[y] == null)
z[y] = [x[i][1]];
else
z[y].push (x[i][1]);
}

/*return z;*/
for (var ii = 0; ii<z.length; ii++)
{ var_box.options[var_c++]=new Option(z[ii]);}
}
</script>

<form method="post" name="frm" action="">
<select name="my_box" size="10" style="width:200px">
</select>
<br />
<input type="button" value="ok" onclick="foo()" />
</form>
Aug 25 '06 #3
There are probably simpler ways to do this, but here's one:
you remember where and how ?
because you are the only solution, I founded at the moment.
Aug 25 '06 #4
On 8/24/2006 10:24 PM, padew wrote:
I have tested (see code below);
but I have some undefinid value.
Now I have:
undefined
undefined
25,27,60,61
undefined
50

anyway the result seem ok;

undefined is my bad code (can you correct?)
but I would like to have the first values 2 and 4
2 25,27,60,61
4 50
-------------
and if I use this
x=[[2,3],[3,4],[1,10],[16,12],[1,15],[2,16],[4,18],[16,19],[1,20],[6,23],[10,25],[10,26],[19,30],[25,32]];

what I must to change in the code?
I think 9 and 10, but change with 27 e 28?
I have now 14 element [ ] in X; is so?
for tests:

function foo ()
{ var var_box=document.frm.my_box;
var var_c=0;

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];

var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (z[y] == null)
z[y] = [x[i][1]];
else
z[y].push (x[i][1]);
}

/*return z;*/
for (var ii = 0; ii<z.length; ii++)
{ var_box.options[var_c++]=new Option(z[ii]);}
}
</script>

<form method="post" name="frm" action="">
<select name="my_box" size="10" style="width:200px">
</select>
<br />
<input type="button" value="ok" onclick="foo()" />
</form>
Perhaps I'm confused. If we start with

[[2,25], [25,27], [27,60], [4,50], [27,61]]

what should the result be?

Perhaps you want it to be

[[2, [25,27,60,61]], [4, [50]]]

or is it something else?

--
_________________________________________
Bob Smith -- bs****@sudleydeplacespam.com

To reply to me directly, delete "despam".
Aug 25 '06 #5
Il Fri, 25 Aug 2006 22:42:10 GMT, Bob Smith ha scritto:
On 8/24/2006 10:24 PM, padew wrote:
>I have tested (see code below);
but I have some undefinid value.
Now I have:
undefined
undefined
25,27,60,61
undefined
50

anyway the result seem ok;

undefined is my bad code (can you correct?)
but I would like to have the first values 2 and 4
2 25,27,60,61
4 50
-------------
and if I use this
x=[[2,3],[3,4],[1,10],[16,12],[1,15],[2,16],[4,18],[16,19],[1,20],[6,23],[10,25],[10,26],[19,30],[25,32]];

what I must to change in the code?
I think 9 and 10, but change with 27 e 28?
I have now 14 element [ ] in X; is so?
for tests:

function foo ()
{ var var_box=document.frm.my_box;
var var_c=0;

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];

var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (z[y] == null)
z[y] = [x[i][1]];
else
z[y].push (x[i][1]);
}

/*return z;*/
for (var ii = 0; ii<z.length; ii++)
{ var_box.options[var_c++]=new Option(z[ii]);}
}
</script>

<form method="post" name="frm" action="">
<select name="my_box" size="10" style="width:200px">
</select>
<br />
<input type="button" value="ok" onclick="foo()" />
</form>

Perhaps I'm confused. If we start with

[[2,25], [25,27], [27,60], [4,50], [27,61]]

what should the result be?

Perhaps you want it to be

[[2, [25,27,60,61]], [4, [50]]]
yes is so;
Aug 26 '06 #6
On 8/26/2006 5:32 AM, padew wrote:
Il Fri, 25 Aug 2006 22:42:10 GMT, Bob Smith ha scritto:
>On 8/24/2006 10:24 PM, padew wrote:
>>I have tested (see code below);
but I have some undefinid value.
Now I have:
undefined
undefined
25,27,60,61
undefined
50

anyway the result seem ok;

undefined is my bad code (can you correct?)
but I would like to have the first values 2 and 4
2 25,27,60,61
4 50
-------------
and if I use this
x=[[2,3],[3,4],[1,10],[16,12],[1,15],[2,16],[4,18],[16,19],[1,20],[6,23],[10,25],[10,26],[19,30],[25,32]];

what I must to change in the code?
I think 9 and 10, but change with 27 e 28?
I have now 14 element [ ] in X; is so?
for tests:

function foo ()
{ var var_box=document.frm.my_box;
var var_c=0;

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];

var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (z[y] == null)
z[y] = [x[i][1]];
else
z[y].push (x[i][1]);
}

/*return z;*/
for (var ii = 0; ii<z.length; ii++)
{ var_box.options[var_c++]=new Option(z[ii]);}
}
</script>

<form method="post" name="frm" action="">
<select name="my_box" size="10" style="width:200px">
</select>
<br />
<input type="button" value="ok" onclick="foo()" />
</form>
Perhaps I'm confused. If we start with

[[2,25], [25,27], [27,60], [4,50], [27,61]]

what should the result be?

Perhaps you want it to be

[[2, [25,27,60,61]], [4, [50]]]

yes is so;
Try this instead

function foo (x)
{
var z={};

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
y = Math.floor (y / 10);
if (y in z)
z[y].push (x[i][1]);
else
z[y] = [x[i][1]];
}

return z;
}

which actually returns

{2:[25,27,60,61], 4:[50]}

which should be easier to use.
--
_________________________________________
Bob Smith -- bs****@sudleydeplacespam.com

To reply to me directly, delete "despam".
Aug 26 '06 #7
now for test I use this, and see the result on popup;
but I not see similar that your result {2:[25,27,60,61], 4:[50]};
I not see 2 and 4;
for use with alert I chenge x (now inner function)
and z={}; in z=[];

can you write the code that you use for se the results?

my modified
function foo()
{

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];
var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
{y = Math.floor (y / 10);}
if (y in z)
{z[y].push (x[i][1]);}
else
{z[y] = [x[i][1]];}
}

return alert(z);
}
Aug 26 '06 #8
On 8/26/2006 6:24 PM, padew wrote:
now for test I use this, and see the result on popup;
but I not see similar that your result {2:[25,27,60,61], 4:[50]};
I not see 2 and 4;
for use with alert I chenge x (now inner function)
and z={}; in z=[];

can you write the code that you use for se the results?

my modified
function foo()
{

x=[[2,25],[25,27],[27,60],[4,50],[27,61]];
var z=[];

for (var i = 0; i < x.length; i++)
{
var y = x[i][0];
if (y 9)
{y = Math.floor (y / 10);}
if (y in z)
{z[y].push (x[i][1]);}
else
{z[y] = [x[i][1]];}
}

return alert(z);
}
Go back to using z={}; and then look at return z.toSource;

--
_________________________________________
Bob Smith -- bs****@sudleydeplacespam.com

To reply to me directly, delete "despam".
Aug 28 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kevin Klein | last post by:
I am talking of C/C++ on unix platform using gcc. So feel free to take off any crossposted NG's if others are not offended, but I seek generic C/C++ and also unix and gcc specific answers. ...
4
by: William | last post by:
I would appreciate your help on the following programming questions: 1. Given an array of length N containing integers between 1 and N, determine if it contains any duplicates. HINT: The...
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
15
by: Oleg Kornilov | last post by:
Hello ! Who can explain why readind from array is fast, but writing (same place) might take a lot of time (I need many loops) How to solve it (declare as static or force some compiler (VC 6.0)...
7
by: Lalasa | last post by:
Hi, Can anybody tell me how many cpu cycles File.copy would take and how many cpu cycles File.Move would take? CFile::Rename in C++ takes just one cpu cycle. As there is no File.Rename in C#,...
7
by: Sam Kong | last post by:
Hello! My question would not be very practical but just out of curiosity. In JavaScript, Array is a subclass of Object. Well maybe not exactly... but sort of... For normal objects, you can...
4
by: Charles | last post by:
Hello Everyone, I have been gettting great feedback from microsoft.public.vc.language group but after doing more searching I think my post should be directed to this group. I am trying to make...
17
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to...
6
by: lukasso | last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.