Urgent.News

What's breaking now, across thousands of outlets.

Tech

The Depths of JavaScript: Minesweeper in 247 Bytes

This 247-byte JavaScript code generates a minimal version of Minesweeper in a web browser. It features an 8x8 randomly generated board, cell opening with left-click, flag toggling with right-click, recursive opening of zero neighboring mine cells, and basic win detection. The code consists of two main functions: 'b', which handles game logic, and 'm', which generates the UI and board.

The UI and board are initialized using a single event listener, 'onmouseup', which uses the 'event.which' property to determine which mouse button was pressed. The code utilizes clever tricks such as defining the 'm' function inside the 'b' function call, ignoring an argument to save bytes, and using the '??=' operator to initialize the board and mines.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at yui.dev →

More in Tech

More from Tuesday 8 September →