Common words finder, containing desired Kanji

This is a continuation from Vocab list (separated by ',') generator -- add reading and meaning

Dropbox - kanji-common.htm - Simplify your life (Must be downloaded to Local first, that is, saved to your computer.)

For example, 焚 becomes

喋屁繋檎蛙儲騙 becomes:

2 Likes

I am stuck at

n = array.length;
n = 1;
for(i=0; i<n; i++) {
    x = array.charAt(i);
    lookUp(x);
}
document.getElementById("input").value = document.getElementById("input").value.slice(1,1000);

Please help me @rfindley, or someone. I don’t know how to use Promise. Asynchronicity is a big problem. I can’t manage to delay function, while maintaining loop. I can still manage it semi-manually, while looking at the console, though.

I might be able to help, what are you trying to do?

Edit: I’m reading the last post and the code

Using For loop with HTML requests. It goes from fetchInfo(x[i]) to fetchInfo(x[i+1]) before HTML requests finishes, so I can’t just use the Loop with += fetchInfo(x[i]).

My guess is I have to go x[0]x[n] simultaneously, as mentioned here Vocab list (separated by ',') generator -- add reading and meaning - #9 by rfindley about Promises – but I don’t know how to apply the code. I failed to try to integrate the suggested code.

Also, I am trying to use single button, or auto-conversion from 喋屁繋檎蛙儲騙 to the result above.

I’m still figuring out the code, so I might be shooting in the dark for a bit, but is there a reason one api call has to wait for the next? if the issue is the “i” variable, try adding “let” right before it:

for(let i=0; i<n; i++) { …

I don’t know how familiar you are with JS or ES6, but the let keyword is really useful for loops with asynchronicity

Edit: Here’s what I’m playing with https://codepen.io/LawlietBlack/pen/pwjGYd?editors=1010

I only get

儲け;もうけ;profit
屁;おなら;wind
蛙;かえる;frog
騙す;だます;to trick
繋ぐ;つなぐ;to connect
喋る;しゃべる;to talk

from the 喋屁繋檎蛙儲騙 seed, not sure why I’m missing some.

Edit 2: got all words now with a filter for common words.

1 Like

Why not share the code on GitHub?

Well, it (mostly) works… I set it to wait 500ms between calls, but I think that’s still a little aggressive, I got 7/80 returns putting in all the joyo kanji at once. can probably add an error handler to re-do those calls later.

Promises aren’t really necessary, you just need to write all the code in the callback function, process_result. Calls don’t really need to wait for the previous ones to get back, either, though I added a setTimout so the server wouldn’t be flooded all at once if I enter a lot of Kanji.

https://codepen.io/LawlietBlack/pen/pwjGYd?editors=1010

Hope that helps, not sure if you wanted to do more for youself :sweat_smile:

Success. One button. Show something without a console, that is, show progress. setTimeout correctly is the key. I use 2000 milliseconds, though.

I might have to learn more about let, CodePen and GitHub. Also, I don’t know how to test something server related. This code doesn’t work on a outside server.

Sorry that my code isn’t clean and uses a bad convention.

///
Edit:

  • I have just understood about flooding the server, and waiting 200 msec. But, I might just wait for the next project to make a improvement, though. It is possible, but shouldn’t be done, to send all the Request (almost) simultaneously, isn’t it?
  • Still, I wait for an arbitrary amount of time, but I can’t really use the result immediately after the process in done? Any way to tell if the process is done or not done?
  • I still didn’t use let.

I’m glad I could be helpful :slight_smile:

It’ll work without let, I think, since the outgoing call happens synchronously (even if the callback doesn’t) and it’s the only thing that directly depends on “i”. The server flood is more to stop 503 errors (server overload). I got less of them the more I waited between calls. The API is kind of slow.

As for telling when it’s complete, I had some code in mine that made a counter for when the calls came back to say when it was complete, but I wasn’t counting when it errored out, so it’s only accurate if there are no errors. It should be fairly straightforward to make a try-catch block to count if it errors out and maybe do the call again / advance the counter.

You can try putting this List of kanji with no vocab? - #16 by VegasVed into this script…

Here is what I get.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.