array is generated by user inputing a random word list that is then organized by word length:
[#] = length of each word in each array
if i have an array ordered as such: - wordList[9] = ["associate", "documents" ]
-
wordList[5] = ["green", "about", "money" ]
-
wordList[3] = ["dog", "cat", "top", "big", "vat" ]
-
wordList[6] = ["floats" ]
-
-
how can i get these desired ordering results:
-
-
wordList[3] = ["dog", "cat", "top", "big", "vat" ]
-
wordList[5] = ["green", "about", "money" ]
-
wordList[6] = ["floats" ]
-
wordList[9] = ["associate", "documents" ]
-
-
my first attempt to reorder, rendered the following:
-
-
wordList[9] = ["dog", "cat", "top", "big", "vat" ]
-
wordList[5] = ["green", "about", "money" ]
-
wordList[3] = ["floats" ]
-
wordList[6] = ["associate", "documents" ]
-
correctly re-ordered each array, but not the [#] associated with it.
1 1470 - wordList[9] = ["associate", "documents" ]
-
wordList[5] = ["green", "about", "money" ]
-
wordList[3] = ["dog", "cat", "top", "big", "vat" ]
-
wordList[6] = ["floats" ]
You are not using associative array syntax.
You have a partially-populated two dimensional subscripted array.
On the assumption that all unmentioned array elements are undefined, and also assuming that the strings in each sub array will all be of the same length, you can copy just the defined elements of wordList to a new array, sort the array using a suitable comparator, then overwrite just the defined elements of wordList with all the elements of the sorted temporary array.
I tried it with no problems.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stefan Richter |
last post by:
Hi,
I want to create an associative Array with a PHP variable (article ID)
as Key
and another associative array as it's value.
How do I instanciate it, how can I fill it?
I want something...
|
by: Abdullah Kauchali |
last post by:
Hi folks,
Can one rely on the order of keys inserted into an associative Javascript
array? For example:
var o = new Object();
o = "Adam";
o = "Eve";
|
by: mark4asp |
last post by:
Suppose I have the following code. It functions to randomly select a
city based upon the probabilities given by the key differences in the
associative array. . Eg.
because the key difference...
|
by: Robert |
last post by:
I am curious why some people feel that Javascript doesn't have
associative arrays. I got these definitions of associative arrays via
goggle:
Arrays in which the indices may be numbers or...
|
by: Derek Basch |
last post by:
Is there any way to associate name/value pairs during an array
initialization? Like so:
sType = "funFilter"
filterTypeInfo = ;
filterTypeInfo = new Array("type" : sType);
I can do it using...
|
by: Karin Jensen |
last post by:
Hi
I am running a PHP program that connects to an Access 2000 database
via ODBC:
$results = odbc_exec($connection_id, $sql_select);
Is it possible to sort the contents of $results? I wish to...
|
by: Paul Lautman |
last post by:
I'm having some trouble understanding what is happening with some array
sorting functions. In all cases, my compare function is:
function compare($x, $y)
{
if ( $x == $y )
return 0;
else if (...
|
by: Rene Nyffenegger |
last post by:
Hello everyone.
I am not fluent in JavaScript, so I might overlook the obvious.
But in all other programming languages that I know and that
have associative arrays, or hashes, the elements in...
|
by: Bosconian |
last post by:
I'm trying to output the contents of an array of associative arrays in
JavaScript. I'm looking for an equivalent of foreach in PHP.
Example:
var games = new Array();
var teams = new...
|
by: mk834tt |
last post by:
When you use an object as an assc array as in:
var aa = new Array();
aa = 2.50;
aa = 3.50;
....
Is there a way to determine the number of entries?
So far I count this way: for (var x in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |