Help converting function to Javascript

I need to create a JS function that does the same thing as this script:
Starbox614 block game script pic (1)
but I don't know where to start. can someone help?
(I don't want the Snap! primitives just called in Javascript though, becuase this needs to be faster that the Snap! version

I personally think it's fast enough. If it isn't, you could try optomizing it furthar.

well, in the game I'm using it in, it makes everything pause for a moment every time it runs, which makes the game not run very smoothly.

In my (limited) experience with Snap !, decomposition may (or may not) help speed up execution to a surprising degree.

Instead of:

  • REPORT (MAP (x) OVER (MAP (y) OVER (z)))

... try:

  • SET (t) to MAP (y) OVER (z)
  • REPORT (MAP (x) OVER (t))

Secondly, why would you want to execute RESHAPE (LIST (0)) TO (20) (20) (4)) multiple times? You could also make that a variable to be calculated beforehand.

If in this case it doesn't work you can always try Javascript (but I personally can't help you with that).

Happy to help, good luck!

that helps a bit, but for some reason the duration to run the function varies between 250ish milliseconds to over 500.

Any blocks that are completely the same and are repeated can be removed. Instead, run the blocks and store the result in a variable.

EDIT: It seems @qw23 beat me to this answer: