A13

by Ebony McCoy

HTML

<input type="textbox" id="content">


<input type="button" value="Add to Dictionary" onclick=createTRIE()>

<input type="button" value="SpellCheck" onclick=checkSpelling()>
<p id="output"></p>

JavaScript

var T = new Trie();
function Node() {
  this.left = null;
  this.right = null;
  this.content = null;
  this.prefixes = 0;
  //this.keys = new Map();
  // this.end = false;
  //this.setEnd = function() {
  //this.end = true;
  //  }
  //this.isEnd = function() {
  // return this.end;
  // }

}
T.protoype.add = function(content) {
  var node = new Node();
	node.content = content;
	
  if (this.left === null) {
    this.left = node;
		this.prefixes = 1;
    return this;
  }
  if (this.right === null) {
    this.right = node;
		this.prefixes = 2;
    return this;
  }

  var Trie = function() {
	var content = document.getElementById("content").value;
	T.add(content);
	T.print();
    this.root = null;

     function AddToTRIE(content, node) {
      if (this.root === null) {
        node = new Node(content);
        this.root = node;
        return this;

      }
      this.root.AddToTRIE(content);
      return this;
    }
    //if (content.length == 0) {
    //  return;
    // } else if (!node.keys.has(content[0])) {
    // node.keys.set(content[0], newNode());
    //  return this.prototype.add(content.substr(1), node.keys.get(content[0]));
    // } else {
    //   return this.prototype.add(content.substr(1), node.keys.get(content[0]));
    // }
    T.prototype.print = function() {
		var display = " ";
      var s = " ";
      if (this.left !== null) {
        s += this.left.print;
				s += " Left: " + this.left.content;
      }
      if (this.right !== null) {
        s += this.right.print;
				 s = s + " Right: " + this.right.content;
      }
      return s;
    }
    
      
      s += "<br />";

      return s;
    }

 

    this.prototype.CheckSpelling = function(word) {
      node = this.root;
      while (word.length > 1) {
        if (!node.keys.has(word[0])) {
          return false;
        } else {
          node = node.keys.get(word[0]);
          word = word.substring(1);
        }
      }
      return (node.keys.has(word) && node.keys.get(word).isEnd())...