【发布时间】:2017-10-21 14:08:20
【问题描述】:
有谁知道我如何将一堆乱七八糟的字母匹配到一个单词,例如,一些可以匹配的函数 一个数组,例如 ["a","c","a","e","c"]; 给一个单词“ace”并给我 1 或者如果不是像 indexOf 或 InArray 那样的 -1 但对于一个混乱的单词。 我用一个有据可查的例子做了一个 js fiddle
请注意,我会将字母数组与 30000 到 50000 个单词进行比较。
https://jsfiddle.net/AlexanderMitrakis/89dchpt8/1/
this.gameletters = []; //Array of Game letters.
//e.g. ["P", "E", "H", "E", "U", "I", "S", "Q", "N"];
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.wordBank 它存储的 wordBank 按字符的字母顺序排序,然后在每个字符数组中按字母顺序排列该字母中的所有单词 this.wordBank[character][characterword ]
标签: javascript jquery arrays function