SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Bubble Sorting Integers....
-
Jun 27, 2002, 09:10 #1
- Join Date
- Jul 2001
- Location
- Grosse Pointe Farms, MI
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bubble Sorting Integers....
Ok, I need to make function "bubble_sort" that takes form data (10 fields) and sorts them.
I am using the standard bubble sorting algorithm and using values (10, 9, 8, 7, 6, 5, 4, 3, 2, 1) the end result should be a list in order 1,2,3,4,5,6,7,8,9,10.
The result I am getting is 1,10,2,3,4,5,6,7,8,9. This makes me believe the function is treating the values as strings.
I am sending the values to the function from a form with 10 textboxes.
My question is if there is a way to cast the values as integers? I check the values to make sure they are integers, but the type is coming as strings...
Anyone done this before?
Ryan
P.S. I am limited to client-side JavaScript Code.Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.
-
Jun 27, 2002, 11:44 #2
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
var i = parseInt(s, 10);
(second argument = radix, specify that you mean decimal numbers)
-
Jun 27, 2002, 13:51 #3
- Join Date
- Jul 2001
- Location
- Grosse Pointe Farms, MI
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks, I'll give it a try when I get home
RyanMichigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.
Bookmarks