JSFiddle - React, Tailwind, and code Playground
by Jeff Santos
HTML
List:
<br/>
<div id="output1"></div>
<br/> List with hash values:
<br/>
<br/>
<div id="output2"></div>
<br/> Hash Values with Index:
<br/>
<br/>
<div id="output3"></div>
JavaScript
var L1 = new List();
var indexes = [];
function Node(_contentA, _contentB) {
this.contentA = _contentA;
this.contentB = _contentB;
this.source = null;
this.next = null;
this.last = null;
return this;
}
function List() {
this.bottom = null;
this.top = null;
this.length = 0;
this.push = function(_contentA, _contentB) {
if (this.bottom == null) {
this.bottom = new Node(_contentA, _contentB);
this.top = this.bottom;
this.length++;
return this;
} else {
var addedNode = new Node(_contentA, _contentB);
addedNode.last = this.top;
this.top.next = addedNode;
this.top = addedNode;
this.length++;
return this;
}
}
this.contentAtoString = function() {
var str = "";
var node = this.bottom;
while (node != null) {
str += node.contentA + " "+ "<br>";
node = node.next;
}
return str;
}
this.toString = function() {
var str = "";
var node = this.bottom;
while (node != null) {
str += node.contentA + " | " + node.contentB + "<br>";
node = node.next;
}
return str;
}
}
List.prototype.crte = function() {
var n = 10;
var node = this.bottom;
for (var i = 1; i <= n; i++) {
this.push(rndm());
}
document.getElementById("output1").innerHTML += this.contentAtoString();
}
List.prototype.hsh = function() {
node = this.bottom;
while (node != null) {
node.contentB = mhash(node.contentA);
node.source = node.contentA;
node = node.next;
}
document.getElementById("output2").innerHTML += this.toString();
}
List.prototype.copy = function() {
var node = this.bottom;
var i = 0;
while (node != null) {
indexes[i] = node.contentB + " | " + node.source;
node = node.next;
i++
}
}
display = function(arr) {
for (i = 0; i < arr.length; i++) {
document.getElementById("output3").innerHTML += arr[i] + "<br >";
}
}
function rndm() {
var s = "";
var valid =...