BubbleSort has absolutely nothing to recommend it except for its catchy name. It isn't the fastest, and it isn't even the easiest to write.
ExtractionSort and InsertionSort are both faster and easier to write. (All three sorts take time proportional to the square of the number of elements being sorted, but the constant of proportionality is smaller by a factor of at least two for the latter two sorts.)
Here's InsertionSort, defined to sort an array A in-place. (If you don't want to sort in-place, make a copy first and then sort the copy in-place.)
function InsertionSort(A) {
var N = A.length;
if (N < 2) { return; }
// Simplify the main loop by first moving the smallest element to the front
var leastInx = 0, leastID = A[0].Id;
for (var i = 1; i < N; ++i) { // note: i++ is cuter, but ++i is often faster
var thisID = A[i].Id; // avoid doing the same work twice
if (thisId < leastId]) {
leastInx = i; leastId = thisId; }}
var tmp = A[0];
A[0] = A[leastInx];
A[leastInx] = tmp;
// Now iterate over the remaining elements, inserting each in its
// proper place among the already-sorted previous elements
for (i = 2; i < N; ++i) {
tmp = A[i];
for (var j = i; A[j-1].Id > tmp.Id; --j) { // no need to test j>0
A[j] = A[j-1]; }
A[j] = tmp; }
}
Of course, the built-in sorts will have running times on the order of N log(N), which will blow away all of these O(N**2) sorts. Writing your own sort routine can be instructive, and I commend it if for no other reason, but if you want speed avail yourself of the skill of the experts.
Arr1andArr2look like for this result or what "placing Arr1 in Arr2" is supposed to mean. Actually I have no idea what you're trying to achieve.alert