<!--This script will add the text box that is used, as well as create a button-->
<!--Programmed by Daniel Eberhart
COP 3530
Assignment 9
3/26/17-->
<H3 id='Title'>COP 3530: Hashing, Assignment 9</H3>
<form id="form">
<p id='Instructions'>Enter the sentence or phrase that you'd like to be hashed:</p>
<p id ='reminder'> Keep in mind, any non alphanumeric character will be removed from the input, and all words will be in lowercase format
</p>
<textarea id='phrase' rows='5' cols='55'>When the going gets tough, the tough get going. Dont let the going get tough before you get going.</textarea>
<br>
<input type="button" value="Phrase to be Parsed" id="parse" onClick="parsePhrase()">
</form>
<div id="output"></div>
JavaScript
// Identify the variables that are needed to store the input
// The variable "Array" is used to store each word as it appears within the phrase set by the user to be parsed. The Bin variable is used to store each word individually
var Array = [];
var bin = [];
//Creating makeNode function
function makeNode(value) {
this.id = 0;
this.content = value;
this.next = null;
this.last = null;
}
// The purpose of using the list function is to properly assign and hold each word from the user specified input phrase for the buckets.
function List(value) {
this.head = new makeNode(value);
this.last = this.head;
}
List.prototype.addNode = function(value) {
if (this.head == null) {
this.head = new makeNode(value);
return this.head;
}
if (this.last == null) {
this.last = new makeNode(value);
this.head.next = this.last;
return this.last;
}
var newNode = new makeNode(value);
this.last.next = newNode;
newNode.last = this.last;
this.last = newNode;
this.id++;
}
makeNode.prototype.asString = function() {
return this.content + " ";
}
List.prototype.print = function() {
var Content = '<br/>';
var node = this.head;
while (node != null) {
Content += node.asString();
node = node.next;
}
return Content;
}
//The function to create the HashTable which in turn will identify the location of each input
var hashTable = new HashTable(); // Global
function parsePhrase() {
var phrase = document.getElementById('phrase').value;
phrase = phrase.toLowerCase();
//converting to lowercase as not to recognize capitalization. For example, "When" would be recognized and placed differently than "when" if the //phrase.toLowerCase were not used.
phrase = phrase.replace(/[^a-zA-Z0-9]/g, ' ');
//The above algorithm is used to filter out any unwanted un-alphanumeric characters that may have been included in the user specified input to be parsed. I ran into the issue...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.