SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Grosse Pointe Farms, MI
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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.

  2. #2
    Sultan of Ping jofa's Avatar
    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)

  3. #3
    SitePoint Zealot
    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


    Ryan
    Michigan looks like your left hand . . . half way between your wrist and the base of your thumb is where I live.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •