JSFiddle - React, Tailwind, and code Playground

by JInks Peng

HTML

<div id="txt">
    <p>1.The Shawshank Redemtion</p>
    <p>2.The Godfather</p>
    <p>3.The Godfather:Part II</p>
    <p>4.Pulp Fiction</p>
    <p>5.Schindler list</p>
</div>

JavaScript

function List() {
	   this.listSize = 0;
	   this.pos = 0;
	   this.dataStore = [];
	   this.clear = clear;
	   this.find = find;
	   this.toString = toString;
	   this.insert = insert;
	   this.append = append;
	   this.remove = remove;
	   this.front = front;
	   this.end = end;
	   this.prev = prev;
	   this.next = next;
	   this.length = length;
	   this.currPos = currPos;
	   this.moveTo = moveTo;
	   this.contains = contains;
	   this.getElement = getElement;
	   this.length = length;
	}

	function append(element) {
	   this.dataStore[this.listSize++] = element;
	}
	 function find(element) {
	      for(var i=0; i < this.dataStore.length; ++i) {
	       if(this.dataStore[i] === element) {
	            return 1;  
	      }
	   }
	    return -1;
	}
	 function  remove(element) {
	   var foundAt = this.find(element);
	   if(foundAt > -1) {
	     this.dataStore.splice(foundAt,1);
	     --this.listSize;
	     return true;
	   }
	   return false;
	}
	function length() {
	   return this.listSize;
	}
	function toString() {
	   return this.dataStore;
	}
	function insert(elem,after) {
	   var insertPos = this.find(elem);
	   if(insertPos > -1) {
	     this.dataStore.splice(insertPos+1,0,elem);  
	     ++this.listSize;
	     return true;
	  }
	  return false;
	}
	function clear() {
	   delete this.dataStore;
	   this.dataStore = [];
	   this.listSize = this.pos = 0;
	}
	function contains(elem) {
	   for(var i = 0; i < this.dataStore.length; ++i) {
	      if(this.dataStore[i] ===  elem) {
	          return true;
	     }
	  }
	     return false;
	}
	function front() {
	  return this.pos = 0;   
	}

	function end() {
	  this.pos = this.listSize - 1;
	}

	function prev() {
	  if(this.pos > 0) {
	    --this.pos;
	  }
	}

	function next() {
	  if(this.pos < this.listSize) {
	    ++this.pos;
	  }
	}

	function currPos() {
	  return this.pos;
	}

	function moveTo(position) {
	  this.pos = position;
	}

	function getElement() {
	  return...