Please help convert this JavaScript to Snap! code

I tried it myself, but the block throws an error when you input only one character in one of them, and always reports 1 when you don't.
https://snap.berkeley.edu/snap/snap.html#present:Username=helicoptur&ProjectName=js%20to%20snap%20block&editMode&noRun

I'll try.

Edit: Very odd:

What exactly is it supposed to do?

Report a percentage between 1 and 0(?) telling how similar the two strings are, I think.
It shouldn’t be saying the variable matrix doesn’t exist, there’s a script variable block right before it…
Edit: Just noticed, it says “Error” instead of “Inside: Error”. That means the variable matrix is being called outside of the definition.

Not looked at code but this is what I do when debugging custom blocks

I work on them outside of the block (if possible) by replacing parameters and script variables with global ones

Makes things much easier to debug

image

Your algorithm calculates Levenshtein distance at the first step. So you fill the matrix with editing distances. But you create only the first row and first column for other rows.
Creating the "matrix" this way should help (also some range shift)
js to snap block script pic (1)

js to snap block script pic (2)
...

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