Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

node.js - How to check occurence time in javascript?

Good evening to all,

I've been trying for several days to create a Discord bot in Javascript that will launch a famous game: Motus.

The goal of the game is to find a word between 7 and 10 characters. To do this, the player submits several words of the same size to see if there are letters in it.

There are three rules: the letters can be misplaced but present in the word, the letters can be absent and the letters can be well placed.

Through the submissions, it is possible to determine which letters are present and which are not.

I have a problem in my case where there are several occurrences in the submissions or the word to be found.

The duplicate letter should be considered false, because if in the word to be found there is only one "t" for example, the misplaced letter or one of the misplaced letters should be removed.

Here is my code where I try to manage the case where the user sends several letters or less in relation to the word to be found.

Currently, he can find the well placed one, but does not cross out the extra one, he only considers them badly placed.

Any help is appreciated.

if ((occurenceUser != occurenceWord) && occurenceWord != 0) {
  array = allIndexOf(userWord, userWord.charAt(i))
  secondarray = allIndexOf(word, userWord.charAt(i))
         
  for (var j = 0; j < array.length; j++)
    for (var k = 0; k < secondarray.length; k++)
      if (array[j] == secondarray[k])
        goodOccurence.push(array[j])
    
        for (var j = 0; j < goodOccurence.length; j++) {
          if (goodOccurence[j] == i) {
            result = result + "**" + userWord.charAt(i) + "** "
            break
          } else if (goodOccurence[j] != i) {
            result = result + userWord.charAt(i) + " "
            break
          } else {
            result = result + "~~" + userWord.charAt(i) + "~~ "
            break
          }
       }
}
question from:https://stackoverflow.com/questions/65925518/how-to-check-occurence-time-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...