JSFiddle - React, Tailwind, and code Playground

by dvjc

HTML

<label>value</label>
<span id="randomNumber1"></span>

JavaScript

function isUndefined( item ){
    return (typeof item == "undefined");
}

function isNull( item ){
    return (typeof item == "object" && item == null);
}

function isEmpty( item ){
    return ( isUndefined(item) || isNull(item) );
}

function isInteger( num ){
    return (typeof num == "number" && Math.round(num) == num);
}

function initializeSmartList(){

  var smartList = {};
  smartList.stack = [];
  smartList.size = 0;
    
  smartList.push = function(num){
    if( isInteger(num) ){
      for( var x = smartList.stack.length; x > 0; x--){
        smartList.stack[x] = smartList.stack[x-1];
      }
      smartList.stack[0] = num;
      smartList.size++;
    }
  }

  smartList.pop = function(){
    var toReturn = smartList.stack[0];
    var replacementStack = [];
    for( var x = 0; x < smartList.stack.length; x++){
      smartList.stack[x] = smartList.stack[x+1];
    }
    smartList.stack[smartList.stack.length-1] = null;
    smartList.size--;
    return toReturn;
  }

  smartList.removeGreater = function( bound ){
    if( isInteger(bound) ){
      var baseLen = smartList.stack.length;
      var truncatedSmartList = initializeSmartList();
      for( var z=0; z<baseLen; z++){
        var smartInteger = smartList.stack[z];
        if( smartInteger <= bound ){
          truncatedSmartList.push( smartInteger );
        }
      }
      smartList = truncatedSmartList;
    }
  }

  smartList.displayStack = function(){
    var cleanStack = [];
    for( var x = 0; x < smartList.stack.length; x++){
      if( !isEmpty(smartList.stack[x]) ){
        cleanStack.push( smartList.stack[x]);
      }
    }
    return cleanStack;
  };

  smartList.displayOrdered = function(){
    cleanList = smartList.displayStack();
    return cleanList.sort( function(a,b){return a-b;} );
  };
    
  smartList.initialize = function(initialList){
    if( !isEmpty(initialList) && initialList.length>0){
      smartList.stack = [];
      for( var y = 0; y < initialList.length; y++){
       ...