Get the latest tech news
The joy of recursion, immutable data, & pure functions: Making mazes with JS
Generating mazes might not be something you do a lot in your typical front-end job. Some might call it a waste of time. Why bother if you’re not a game developer? Who needs that kind of thing? Sure, it might not be essential, but it’s a lot of fun. Building mazes also presents interesting real-world challenges. How do we deal with random numbers if we’re creating pure functions? How do we implement a repetitive algorithm without using loops? How do we work effectively with immutable data structures? And most importantly, can we have some fun while we’re at it?
The x-value for the point is i modulo n. The y-value is i divided by n. And the right item in the pair is an empty list. I won’t go into the details of how this one works, but it’s using prime numbers to generate a pseudorandom sequence. Because it helps you think differently Orson Welles supposedly said “The enemy of art is the absence of limitations.” 1 That is to say, imposing constraints encourages creativity.
Or read this on Hacker News