...

View Full Version : Bubble Sort Array



Bullers
08-14-2008, 01:31 AM
Hello, I need to sort this array in ascending order by ISBN number using a bubble sort. Can anyone help me? Thank you.


var books = [];
books[0] = "1565923928:Programming In javascript:2290:950";
books[1] = "2010948473:Java The Definitive Guide:1499:700";
books[2] = "1098767854:Javascript For Beginners:999:600";

A1ien51
08-14-2008, 03:35 AM
You would be better off using an object or another array to avoid a split

But as you asked:



var books = [];
books[0] = "1565923928:Programming In javascript:2290:950";
books[1] = "2010948473:Java The Definitive Guide:1499:700";
books[2] = "1098767854:Javascript For Beginners:999:600";


function isbn(a,b){
var n1 = a.split(":")[0];
var n2 = b.split(":")[0];
return n1>n2
}

alert(books.sort(isbn).join("\n"));


Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum