JSFiddle - React, Tailwind, and code Playground

JavaScript

function  CArray(numElems) {
  	this.dataStore = [];
  	this.pos = 0;
  	this.numElems = numElems;
  	this.insert = insert;
  	this.toString = toString;
  	this.clear = clear;
  	this.setData = setData;
  	this.swap =swap;
    this.shellsort1 =shellsort1;
  	for(var i = 0; i < numElems; ++i) {
  		this.dataStore[i] = i;
  	}
  }
  function  setData() {
  	for(var i = 0; i < this.numElems; ++i) {
  		this.dataStore[i] = Math.floor(Math.random() * 100);
  	}
  }
  function clear() {
  	for (var i = 0; i <  this.numElems; ++i) {
  		this.dataStore[i] = 0;
  	}
  }
  function insert(elem) {
  	this.dataStore[this.pos++] = elem;
  }
  function toString() {
  	var str = "";
  	for(var i = 0; i < this.dataStore.length; ++i) {
  		str += this.dataStore[i] + " ";
  		if( i > 0 && (i+1) %10 === 0) {
  			str += "\n";
  		}
  	}
  	return str;
  }
  function swap(arr,index1,index2) {
  	var temp = arr[index1];
  	arr[index1] = arr[index2];
  	arr[index2] = temp;
  }
 function shellsort1() {
    var N = this.dataStore.length,h = 1;
    while(h < N/3) {
      h = 3 * h + 1;
    }
    while(h > 0) {
      for(var i = h; i < N; ++i) {
        for(var j = i; j >= h && this.dataStore[j] < this.dataStore[j-h]; j -= h) {
          swap(this.dataStore, j ,j-h);
        }
      }
      h = (h-1)/3;
    }
 }
 
var myNums = new CArray(10);
myNums.setData();
console.log(myNums.toString());
myNums.shellsort1();
console.log(myNums.toString());