473,805 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Move Array entry up or down in the Array

Is there an effecient way to move an array entry up or down in the array?

For example. Say you have an array of 5 entries. They are all strings by the
way.

myArray = ("entry0","entr y1","entry2","e ntry3","entry4" );

What is needed is a mechanism/function to move any of the array entries up
or down in the array. I have been trying by first splice(selected Entry) out
of the Array, then a couple of slice() and then concat() them all back
together but this seems very clumsy.

Does anyone know of a more elegant way to accomplish this?

Regards,
David J.
Nov 8 '06 #1
5 7963
VK

David wrote:
Is there an effecient way to move an array entry up or down in the array?

For example. Say you have an array of 5 entries. They are all strings by the
way.

myArray = ("entry0","entr y1","entry2","e ntry3","entry4" );

What is needed is a mechanism/function to move any of the array entries up
or down in the array. I have been trying by first splice(selected Entry) out
of the Array, then a couple of slice() and then concat() them all back
together but this seems very clumsy.

Does anyone know of a more elegant way to accomplish this?
<script type="text/javascript">
var arr = [0,1,2,3];

var tmp = arr.splice(3,1) ;
arr.splice(2,0, tmp);

alert(arr); // 0,1,3,2
</script>

IMHO you are seeking for List functionality rather than for Array's
one. See for instance
<http://groups.google.c om/group/comp.lang.javas cript/msg/19ac11e0164d8ab 4>
as well as the whole thread which contains a valuable criticism.

Nov 8 '06 #2
I have seen your List class on
<http://groups.google.c om/group/comp.lang.javas cript/msg/19ac11e0164d8ab 4>

You $add() method is so cool !!

Nov 8 '06 #3
VK

Lich_Ray wrote:
I have seen your List class on
<http://groups.google.c om/group/comp.lang.javas cript/msg/19ac11e0164d8ab 4>

You $add() method is so cool !!
As indicated at the top of the linked post, the coolest (IMHO) part
with splice-zero was suggested by poster signing as "Ray".

Nov 8 '06 #4
>Is there an effecient way to move an array entry up or down in the array?
<script type="text/javascript">
var arr = [0,1,2,3];

var tmp = arr.splice(3,1) ;
arr.splice(2,0, tmp);

alert(arr); // 0,1,3,2
</script>

IMHO you are seeking for List functionality rather than for Array's
one. See for instance
<http://groups.google.c om/group/comp.lang.javas cript/msg/19ac11e0164d8ab 4>
as well as the whole thread which contains a valuable criticism.
Thank you, that is a very effecient way to do it...

David J.
Nov 8 '06 #5
Lich_Ray wrote:
I have seen [VK's] List class on
<http://groups.google.c om/group/comp.lang.javas cript/msg/19ac11e0164d8ab 4>

You $add() method is so cool !!
Despite the poor implementation?

Mike
Please quote when replying to posts in this group.
Nov 8 '06 #6

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

Similar topics

9
3389
by: sathya | last post by:
I was going through an Boyer-Moore-Horspool pattern match, I saw a array inside a array, like the below, skip ] = patlen - i - 1; The array is decleared as int skip; unsigned char *pat;
1
57870
by: Samuel R. Neff | last post by:
Are there any differences between using Array.Length and Array.GetUpperBound(0) on a one-dimensional array? We have a team of developers and most people use Array.Length but one developer uses GetUpperBound(0). I'd like the code to all be consistent but would like to know if there is any other reason I can provide to justify using only Array.Length instead of GetUpperBound(0). I read that Array.Length has special meaning to the...
6
2242
by: routeslip | last post by:
I'm refering to an entry in an array by it's string key, as in foo. Is there a way to get the numeric index of that array without iterating through the entire array? What I need to do is find the "next" or "previous" entry in the array, but the keys are strings, instead of numerical indeces. thanks for your help.
1
1832
by: beachboy | last post by:
How I can Move up or down XmlElement? Please advise. Thanks in advanced.
2
2158
by: beachboy | last post by:
How I can Move up or down XmlElement? Please advise. Thanks in advanced.
7
1758
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
0
1594
by: K B | last post by:
Hi again, I have a treeview, I would like to select a node, then click on an up or down button and move the node accordingly, updating the xmlDocument each time. For example, if I select a 2nd level element I want to move that up/down in that sibling node set...important that I move all the children, if any, as well. Could someone point me to a good reference? (Not drag and drop).
2
11605
by: james | last post by:
Hi Guys, Would anyone mind telling me the difference between Array.Clone and Array.CopyTo? I was asked this during an interview and got partial credit for saying they were basically the same because they create shallow copies. I ran ILDasm on Array and saw that they do the copy using different IL calls. Does anyone know why one would be preferred over the other? Thanks,
4
1599
by: mattmao | last post by:
Hello everyone: Recently we were given this example: int array={0,1,2,3,4,5,6,7,8,9}; Of course if you printf("%d", array); the output would be 2. But our tutor raised such a confusing debate:
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.