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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of joy

joy

Photo of mazes

mazes

Photo of recursion

recursion

Related news:

News photo

Sword of the Sea is an expression of the joy of movement in video games - PS Plus subscribers are in for an absolute treat

News photo

The Joy of Mixing Custom Elements, Web Components, and Markdown

News photo

Writing toy software is a joy