App/script.js
// Partition(): Places the (r)th bar at the correct position 
Places the (r)th bar at the correct position
Places the ( r ) th bar at the correct position
async function Partition(l, r, d) {
	let i = l - 1;
	let j = l;
	let id = bars[r].split('id="')[1].split('"')[0];
	document.getElementById(id).style.backgroundColor = selected;
	for (j = l; j < r; j++) {
		let a = parseInt(bars[j].split(/[:%]/)[1]);
		let b = parseInt(bars[r].split(/[:%]/)[1]);
		if (a < b) {
			i++;
			let curr_id = bars[i].split('id="')[1].split('"')[0];
			let nxt_ele = bars[j].split('id="')[1].split('"')[0];
			document.getElementById(curr_id).style.backgroundColor = chng;
			document.getElementById(nxt_ele).style.backgroundColor = chng;
			let temp = bars[i];
			bars[i] = bars[j];
			bars[j] = temp;
			await Sleep(d / 3.0);
			container.innerHTML = bars.join('');
			document.getElementById(curr_id).style.backgroundColor = chng;
			document.getElementById(nxt_ele).style.backgroundColor = chng;
			document.getElementById(id).style.backgroundColor = selected;
			let sound = MapRange(document.getElementById(curr_id).style.height.split('%')[0], 2, 100, 500, 1000);
			beep(100, sound, d)
			await Sleep(d / 3.0)
			document.getElementById(curr_id).style.backgroundColor = def;
			document.getElementById(nxt_ele).style.backgroundColor = def;
		}
	}
	let temp = bars[i + 1];
	bars[i + 1] = bars[r];
	bars[r] = temp;
	container.innerHTML = bars.join(' ');
	document.getElementById(id).style.backgroundColor = selected;
	await Sleep(d / 3.0);
	document.getElementById(id).style.backgroundColor = def;
	return i + 1;
}
async function Partition ( l , r , d ) { let i = l - 1 ; let j = l ; let id = bars [ r ] . split ( 'id="' ) [ 1 ] . split ( '"' ) [ 0 ] ; document . getElementById ( id ) . style . backgroundColor = selected ; for ( j = l ; j < r ; j ++ ) { let a = parseInt ( bars [ j ] . split ( / [:%] / ) [ 1 ] ) ; let b = parseInt ( bars [ r ] . split ( / [:%] / ) [ 1 ] ) ; if ( a < b ) { i ++ ; let curr_id = bars [ i ] . split ( 'id="' ) [ 1 ] . split ( '"' ) [ 0 ] ; let nxt_ele = bars [ j ] . split ( 'id="' ) [ 1 ] . split ( '"' ) [ 0 ] ; document . getElementById ( curr_id ) . style . backgroundColor = chng ; document . getElementById ( nxt_ele ) . style . backgroundColor = chng ; let temp = bars [ i ] ; bars [ i ] = bars [ j ] ; bars [ j ] = temp ; await Sleep ( d / 3.0 ) ; container . innerHTML = bars . join ( '' ) ; document . getElementById ( curr_id ) . style . backgroundColor = chng ; document . getElementById ( nxt_ele ) . style . backgroundColor = chng ; document . getElementById ( id ) . style . backgroundColor = selected ; let sound = MapRange ( document . getElementById ( curr_id ) . style . height . split ( '%' ) [ 0 ] , 2 , 100 , 500 , 1000 ) ; beep ( 100 , sound , d ) await Sleep ( d / 3.0 ) document . getElementById ( curr_id ) . style . backgroundColor = def ; document . getElementById ( nxt_ele ) . style . backgroundColor = def ; } } let temp = bars [ i + 1 ] ; bars [ i + 1 ] = bars [ r ] ; bars [ r ] = temp ; container . innerHTML = bars . join ( ' ' ) ; document . getElementById ( id ) . style . backgroundColor = selected ; await Sleep ( d / 3.0 ) ; document . getElementById ( id ) . style . backgroundColor = def ; return i + 1 ; }
Partition(): Places the (r)th bar at the correct position
Partition () : Places the ( r ) th bar at the correct position