473,396 Members | 1,712 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,396 software developers and data experts.

Is it possible to sort an array with the alphabet string in reverse?

28
Hi,

Does anyone know if its possible to sort an array with the alphabet string in reverse? z-a? The only one I know of is reverse but that doesn't work. Could someone please help I would very much appreciate any help.
Thank you in advance.
Feb 27 '11 #1

✓ answered by dgreenhouse

You'll need to store the values then call reverseString() when you've completed taking input.

4 2422
dgreenhouse
250 Expert 100+
Are you saying you want to reverse each array element's string value first?

If so, maybe this will help:

Expand|Select|Wrap|Line Numbers
  1. function reverseReverseArray(array_in) {
  2.   for (i=0; i<array_in.length; i++) {
  3.     array_in[i] = reverseString(array_in[i]);
  4.   }
  5.   array_in.reverse();
  6. }
  7.  
  8. function reverseString(s_in) {
  9.     var s_out = "";
  10.     var i = s_in.length;
  11.     while (i>0) {
  12.         s_out += s_in.substring(i-1,i);
  13.         i--;
  14.     }
  15.     return s_out;
  16. }
  17.  
Feb 28 '11 #2
seanh
28
Hi dgreenhouse,

Thank you so much for your response.

I'm not really sure what its called but here's an example with code:

If I input letter a then submit, then letter b and submit..., so I type: a , b, c, d, e

is it possible to get e, d, c, b, a

When I put your function which most likely 100% I'm using it wrong I get:
e, c, a, b, d

can you show me how to use your function I'm not really sure how the second function works.

Thank you again,
-sean.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <script type="text/javascript" language="javascript">
  4.         var counter=0;
  5.         var alpha =new Array();
  6.  
  7.         function reverseAlpha() {
  8.             var letterFromTxtBox;
  9.               letterFromTxtBox = document.forms[0][0].value;
  10.               alpha[counter]=letterFromTxtBox;         
  11.            lastLetter=alpha[counter];
  12.  
  13.             if ((alpha )){
  14.                       counter++;
  15.                      alert(" letters: " +  alpha.reverse()+"\n"+ " Last letter typed: " + lastLetter ) ;
  16.             }      
  17.         } 
  18.  
  19.    function reverseReverseArray(alpha) {
  20.     for (i=0; i<alpha.length; i++) {
  21.        alpha[i] = reverseString(alpha[i]);
  22.      }
  23.     alpha.reverse();
  24.    }
  25.  
  26.    function reverseString(s_in) {
  27.        var s_out = "";
  28.        var i = s_in.length;
  29.        while (i>0) {
  30.            s_out += s_in.substring(i-1,i);
  31.            i--;
  32.        }
  33.        return s_out;
  34.    }
  35.  
  36.   </script>
  37.   </head>
  38.  
  39.   <body>
  40.       <form >
  41.           Letter:  <input type="text" name="textBox" /><br />
  42.              <input type="button"  value="Submit" onClick="reverseAlpha();" name="Submit" />
  43.       </form>
  44.  
  45.   </body>
  46. </html>
Feb 28 '11 #3
dgreenhouse
250 Expert 100+
You'll need to store the values then call reverseString() when you've completed taking input.
Mar 1 '11 #4
seanh
28
Hi dgreenhouse,
Thank you so much for your kind reply and generosity with your time.
-sean
Mar 1 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: SASRS | last post by:
Here is my code. I am trying to see if I can put a %@ LANGUAGE="VBSCRIPT" %> <% FieldA = Request.QueryString("A") FieldB = Request.QueryString("B") FieldC = Request.QueryString("C") ...
6
by: Ksenia Marasanova | last post by:
Hi, I have a list that contains nodes from a tree. Each node is a class instance, but I'll use dictionary here to simplify the example. So the list looks like this: Where 'ord_number' is...
0
by: aaa | last post by:
I am considering buying LLBLGen Pro for my Windows.Forms application. I want to use DataGrid control to present data in my database tables. One of features I rely on is easy data sorting based on...
1
by: sloan | last post by:
Ok, I've gotten somewhat handy with the new GridView. And I have it bound to a business object datasource, via the ObjectDataSource. Lets say I have 3 databound columns EmpID,...
1
by: Dave | last post by:
Maybe I'm missing something, but in the Sorting event of the Gridview, the GridViewSortEventArgs.SortDirection is always Ascending. I'm not sure why?
1
by: richard | last post by:
OK, I have got bi-directional datagrid sorting down, have a created a nice sorting class. My question, how can I add sorting to more than one datagrid on the same page? Everything I have tried has...
3
by: > Adrian | last post by:
In VS 2003 I could sort a column in a list view using the code below, hover, in V2005 I get this error: Error 1 Using the generic type 'System.Collections.Generic.IComparer<T>' requires '1' type...
11
by: Trent | last post by:
Running this I see that on first run, both bubble and selection sort have 9 sort counts while insertion sort has ZERO. With a sorted list, should this be ZERO for all? Also bsort and Ssort have...
11
by: michaelperl | last post by:
hi all ! I need some help please I'm using a database tool for developing and driving dynamic content. With the tool I use I make queries based on my tables and I set the sorting order of my...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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 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.