JSFiddle - React, Tailwind, and code Playground

by Jeff Santos

HTML

<input type="textbox" id="text" />
<input type="button" onClick="addT(document.getElementById('text').value);" value="Add To Dictionary" />
<input type="button" onClick="chkS(document.getElementById('text').value);" value="Spell Check" />
<div id="output" />

JavaScript

function trie(id, content, last) {
  this.id = id;
  this.next = null;
  this.last = last;
  this.content = content;
  this.values = new List();

  this.add = function(word, pos = 0) {
    if (pos < word.length) {
      var char = word.toLowerCase().charAt(pos);
      var aNode = null;
      var index = this.values.indexOf(char);
      if (index == null) {
        aNode = this.values.append(char);
      } else {
        aNode = this.values[index];
      }
      pos++;
      aNode.add(word, pos);
    }
  }

  this.chk = function(word, pos = 0) {
    if (pos < word.length) {
      var char = word.toLowerCase().charAt(pos);
      var nNode = null;
      var index = this.values.indexOf(char);
      if (index == null) {
        return false
      }
      nNode = this.values[index];
      pos++;
      return nNode.chk(word, pos);
    }
    return true;
  }
}

function List() {
  this.head = null;
  this.length = 0;

  this.append = function(content) {

    if (this.head != null) {
      this.goto_end();
    }

    var node = new trie(this.length, content, null);


    if (this.head != null) {
      node.last = this.head;
      this.head.next = node;
    }


    this[this.length] = node;


    this.head = node;
    this.length++;

    return node;
  }

  this.goto_begin = function() {

    while (this.previous()) {}
  }

  this.goto_end = function() {

    while (this.next()) {}
  }

  this.previous = function() {
    if (this.head.last != null) {
      this.head = this.head.last;
      return true;
    } else {
      return false;
    }
  }

  this.next = function() {
    if (this.head.next != null) {
      this.head = this.head.next;
      return true;
    } else {
      return false;
    }
  }

  this.clear = function() {
    this.head = null;
    this.length = 0;

    for (var prop in this) {
      if (this[prop] instanceof Node) {
        delete this[prop]
      }
    }
  }

  this.indexOf = function(value) {
    if (this.length != 0) {
      for (var prop in this)...