View Single Post
Old 08-31-2007, 12:12 PM   #2 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Actually, never mind, I've got it. I swept the cobwebs from my mind and put it to work. Heres what I've come up with:

Code:
function swap(array,index1,index2) {
	var firstRep = array[index1];
	var secondRep = array[index2];
	var output = new Array();
	for (ar in array) {
		if (ar==index1) {
			output[index1] = secondRep;
		} else if (ar==index2) {
			output[index2] = firstRep;
		} else {
			output[ar] = array[ar];
		}
	}
	return output;
}
function test() {
	var output = "";
	var start = new Array("a","b","c","d","e","f","g");
	for (st in start) {
		output += start[st];
	}
	alert(output);
	output = "";
	var newArray = swap(start,1,3);
	for (ne in newArray) {
		output += newArray[ne];
	}
	alert(output);
}
__________________
Stuff4Web.co.uk - The ultimate resource for webmasters

50% off all orders £1-£50! Just enter the code AGSIG01 at the checkout! Offer ends: 01/09/2008
markster is offline   Reply With Quote