JSFiddle - React, Tailwind, and code Playground

by Michael Dibbets

JavaScript

function PhysicalLocation(name,postcode,town,county) {
    this.name = name;
  this.postcode = postcode;
  this.town = town;
  this.county = county;
}
function SearchBase() {
  this.postcode = {};
  this.town = {};
  this.county = {};
  
  }
SearchBase.prototype.TOWN = 1;
SearchBase.prototype.POSTCODE = 2;
SearchBase.prototype.COUNTY = 3;

function PostcodeRegion(key) {
   this.isRegion = true;
   this.regionKey = key;
}
SearchBase.prototype.feed = function(arrayList){
  for(item in arrayList) {
    var current = arrayList[item];
    var split = current.postcode.split(' ');
    var first = split[0];
    var last = split[1];
    if(typeof this.postcode[first] === 'undefined') {
      this.postcode[first] = new PostcodeRegion(first);
    }
    if(typeof this.postcode[first][last] === 'undefined') {
        this.postcode[first][last] = []; 
    }
    this.postcode[first][last].push(current);
    if(typeof this.county[current.county] === 'undefined') {
       this.county[current.county] = [];
    }
    this.county[current.county].push(current);
    if(typeof this.town[current.town] === 'undefined') {
       this.town[current.town] = [];
    }
    this.town[current.town].push(current);
  }
}
SearchBase.prototype.isPostcodeRegion = function(what) {
  return what instanceof PostcodeRegion;
  }
SearchBase.prototype.seek = function(part,searchtype) {
  if(typeof searchtype === 'undefined') {
    throw new Error("Yea, if you could define a searchtype, that'd be great");
    }
  if(searchtype === SearchBase.TOWN) {
    return this.seekByTown(part);
  }
  if(searchtype === SearchBase.COUNTY) {
     return this.seekByCounty(part);
    }
  if(searchtype === SearchBase.POSTCODE) {
    return this.seekByPostcode(part);
    }
  throw new Error("unsupported search type supplied");
 }
SearchBase.prototype.seekByCounty = function(part) {
  var list = [];
  Query.map(this.county,function(entry,key) { 
    if(key.startsWith(part)) {
      list.concat(entry);
    }
    return list;
 ...