Home Manual Reference Source Test Repository

src/sort/insertionsort.js


export function insertionsort ( compare, a, i, j ) {

	for ( let k = i + 1 ; k < j ; ++k ) {

		let t = k;
		const o = a[t];

		while ( t --> i && compare( a[t], o ) > 0 ) {
			a[t + 1] = a[t];
		}

		a[t + 1] = o;
	}
}