This is a very simple implementation of a maze generation algorithm in JavaScript. It is written for a friend of mine who is writing a game for an old Amstrad. He was looking for a simple maze generator that he could translate into Amstrad-compatible C-code. Because of this, it has to be reasonably conservative with memory, and not use too much recursion.
I recalled finding an old maze generation algorithm in a PC user group magazine many years ago, written in BASIC. At the time, I was fascinated with it and translated it into Java code. When my friend brought up his maze-generation algorithm, I decided to see if I could remember how it went, and write it in JavaScript.
The maze is drawn on a grid of boxes. Each box can be empty or filled. Filled boxes represent walls, while empty boxes represent the maze. There is only one possible path through the maze. That is, there are never any loops.
Usually, I would refactor my code a lot more than you see here. I would remove all my loops, and replace them with map/filter/reduce etc. And I would strive to minimise the use of mutable data and global variables. But, since this is going to be translated into Amstrad-C anyway, I thought I would leave it as is.