Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.






                // First write the swap function, which is just a helper function to swap values of the array.
function swap(array, i, j) {
	var temp = array[i];
	array[i] = array[j];
	array[j] = temp;

function quicksortLomuto(array, left, right) {
	// left-pointer would be the index of the first element which is 0 and right-pointer would be the index of the last element which would be (length -1).
	left = left || 0;
	right = right || array.length - 1;

	var pivot = partitionLomuto(array, left, right);

	if (left < pivot - 1) {
		quicksortLomuto(array, left, pivot - 1);

	if (right > pivot) {
		quicksortLomuto(array, pivot - 1, right)

	return array;

function partitionLomuto(array, left, right) {
	// Lomuto algorithm always uses the last element, array[right], for the pivot.
	var pivot = right;
	var i = left;

	/*The logic under Lomuto is, we start from the leftmost element and keep track of index of smaller (or equal to) elements as j. While traversing, if we find a smaller element, we swap current element with arr[j]. Otherwise we ignore current element.*/
	for (var j = left; j < right; j++) {
		if (array[j] <= array[pivot]) {
			swap(array, i, j);
	swap(array, i, j);
	return i;

/******************* Testing Lomuto algorithm *********************/

function getRandomInt(min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
	// By adding 1, I am making the maximum inclusive ( the minimum is inclusive anyway). Because, the Math.random() function returns a floating-point, pseudo-random number in the range from 0 inclusive up to but not including 1

var arr = [];

for (var i = 0; i < 5; i++) { //initialize a random integer unsorted array
	arr.push(getRandomInt(1, 100));

console.log("Unsorted array: ");
console.log(arr); //printing unsorted array

arr = quicksortLomuto(arr, 0, arr.length - 1);
console.log("Sorted array: ");

/* Output:
Unsorted array: 
[ 83, 52, 89, 42, 6, 87, 50, 17, 34, 96 ]
Sorted array: 
[ 6, 17, 34, 42, 50, 52, 83, 87, 89, 96 ]
[Finished in 0.1s] */