Sort Array with Position in Javascript

Sort an array with position and the rest set as it is.

–JS File

function sortP(a, b){
	var unSort = b.slice(0, b.indexOf(a));
	var nsort = b.slice(b.indexOf(a), b.length).sort();
	return unSort.concat(nsort);
}

sortP(2, [5,2,6,8,3,4,7])

You will see now.

[5, 2, 3, 4, 6, 7, 8]

Leave a Reply

Your email address will not be published. Required fields are marked *