Action

Fake Wordle

Posted by agiletortoise, Last update over 2 years ago

Extremely naive action to generate a fake Wordle result grid based on the number of guesses provided in the prompt.

Steps

  • script

    // setup
    const n = "⬛";
    const m = "🟨";
    const y = "🟩";
    const gridWidth = 5;
    
    // util to randomize array elements
    function shuffle(array) {
      let currentIndex = array.length,  randomIndex;
      while (currentIndex != 0) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex--;
        [array[currentIndex], array[randomIndex]] = [
          array[randomIndex], array[currentIndex]];
      }
      return array;
    }
    
    // creates fake wordle result
    function generate(guesses) {
    	let s = "";
    	let correct = Math.floor(Math.random() * 2);
    	let close = Math.floor(Math.random() * 2);
    	for (let ix=0; ix<guesses - 1; ix++) {
    		let arr = Array(correct).fill(y);
    		arr = arr.concat(Array(close).fill(m));
    		if (close+correct < gridWidth) {
    			arr = arr.concat(Array(gridWidth - close - correct).fill(n));
    		}
    		shuffle(arr)
    		s += arr.join("") + "\n";
    		if (correct < gridWidth - close - 1) {
    			correct++;
    		}
    	}
    	s += y.repeat(gridWidth) + "\n";
    	return s;
    }
    
    // prompt for number of guesses
    let p = new Prompt();
    p.title = "Fake Wordle"
    p.addSelect("guesses", "Number of Guesses", ["1", "2", "3", "4", "5", "6"], ["3"], false);
    p.addButton("Create");
    
    if (p.show()) {
    	// insert fake wordle result 
    	editor.setSelectedText(generate(parseInt(p.fieldValues["guesses"])));
    }
    
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.