乱码生成器

问题描述

将字符串作为输入并根据提供的字典生成所有可能的有效单词(最少 3 个字符)的程序。 config:dictionary.txt(https://www.scrapmaker.com/download/data/wordlists/dictionaries/dictionary.txt) 包含每行单词列表。

示例: 输入:刀片 输出: 坏,小伙子,LED,ALE,... 秃头、铅、流血…… 废话,废话,..

在这个程序中,我正在获取一个文本文件生成所有可能的单词,但我无法理解如何将文本文件与我的代码匹配并返回公共数组。

const filetoArr = async () => {
    let arr = [];
    let file = fetch("./dictionary.txt");
    file = file.then(response => response.text());
    arr = await file.then(line =>  line.split("\n"));
    }
    filetoArr();
    
    function swap(chars,i,j) {
        var tmp = chars[i];
        chars[i] = chars[j];
        chars[j] = tmp;
    }
    
    function getAnagrams(input) {
        var counter = [],anagrams = [],chars = input.split(''),length = chars.length,i;
    
        for (i = 0; i < length; i++) {
            counter[i] = 0;
        }
    
        anagrams.push(input);
        i = 0;
        while (i < length) {
            if (counter[i] < i) {
                swap(chars,i % 2 === 1 ? counter[i] : 0,i);
                counter[i]++;
                i = 0;
                anagrams.push(chars.join(''));
            } else {
                counter[i] = 0;
                i++;
            }
        }
    
        return anagrams;
    }
    
    const input = "BLADE";
    let output = getAnagrams(input);
    console.log(output);
    
    function getCommon(arr1,arr2) {
        var common = [];                   // Array to contain common elements
        for(var i=0 ; i<arr1.length ; ++i) {
          for(var j=0 ; j<arr2.length ; ++j) {
            if(arr1[i] == arr2[j]) {       // If element is in both the arrays
              common.push(arr1[i]);        // Push to common array
            }
          }
        }
        return common;                     // Return the common elements
      }
    getCommon(arr,output);
```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)