JSFiddle - React, Tailwind, and code Playground

by AlexanderMitrakis

HTML

Gameletters: <p class="gameletters"></p> <br/>

RemoveDuplicate Array: <p class="DuplicateArray"></p> <br/>

PossibleSolution: <p class="PossibleSolution">Need to find !!</p> <br/>

CSS

p {
	color: red;
	display: inline-block;
}

JavaScript

session = new startwordgame();
function startwordgame() { // Start word game.

this.gameletters = ["a","a","b","c","d"]; //Array of Game letters. 
                //e.g. ["P", "E", "H", "E", "U", "I", "S", "Q", "N"];
								
$(".gameletters").html(this.gameletters);


this.possiblesolution = new String(); //highest solution within gameletters
                //e.g. "QUEENSHIP" (related to above letters) 

this.wordBank = new Array(); 
               //array of arrays structure is formated around alphabet with an array for each character:
               /* 
                a: Array(7295)
                b:Array(7271)
                c:Array(11381)
                d:Array(7216)
                ... 
                y:Array(607)
                z:Array(623)
             */
this.loadWords = function(wordArray){ //Loads all character words into array of arrays. 

		var character = wordArray[0].charAt(0);  
//Gets the character from the pos(first word, first character) To set the array name to so.

		if (!character) { //If couldnt find character through error.
			console.warn("Error cannot find character !"); 
		}


		//WordBank[Character] = character array from wordBank.js
		this.wordBank[character] = wordArray; 
}

//Send Wordfile session object so it can call wordbank 
loadWordsfile(this);
	
this.removeDuplicates = function(){
    var letters = this.gameletters.slice();
		var uniqueletters = [];
		$.each(letters, function(i, el){
		    if($.inArray(el, uniqueletters) === -1) uniqueletters.push(el);
		});
		return uniqueletters;
}
			
this.getPossibleSolution = function(){
    		var tempPossibleSolution;
    		var removedDupArray = this.removeDuplicates();
				
				$(".DuplicateArray").html(removedDupArray);
    		
    		console.log(removedDupArray);
    		var NoComparisons = 0;
				
    		for (var i = 0; i < removedDupArray.length; i++) {
  			var item = removedDupArray[i].toLowerCase();
					for (var j = 0; j < this.wordBank[item].length; j++) {
						if...