shouting 

RECURSIVE IIFE SOLUTION :DDDDD

re: shouting 

@vaporeon_ a special javascript syntax that lets you declare and execute a function simultaneously :DDDDD

Follow

re: shouting 

@vaporeon_ IT'S BEAUTIFUL 🥹

/**
* @param {character[][]} grid
* @return {number}
*/
var numIslands = function(grid) {
const seen = new Set;
const R = grid.length, C = grid[0].length;

let count = 0;
for (let x = 0; x < R; ++x)
for (let y = 0; y < C; ++y)
if (!seen.has(`${x}-${y}`) && grid[x][y] === '1')
(function crawl(grid, x, y, seen) {
if (x < 0 || x >= R || y < 0 || y >= C) return;

const key = `${x}-${y}`;
if (seen.has(key)) return;
seen.add(key);

if (grid[x][y] === '0') return;

crawl(grid, x + 1, y, seen);
crawl(grid, x, y + 1, seen);
crawl(grid, x - 1, y, seen);
crawl(grid, x, y - 1, seen);
})(grid, x, y, seen), count++;

return count;
};

re: shouting 

@wallhackio Instead of CW re:shouting, this should have CW JavaScript

JavaScript 

@wallhackio What kind of syntax is seen.has(`${x}-${y}`)? Looks interesting. What do the backticks ` do?

re: JavaScript 

@vaporeon_ it's a neat little syntax that languages have been introducing lately to make string interpolation simpler.

Instead of String(x) + "-" + String(y) you do ${x}-{y} (I can't figure out how to add the surrounding backticks in markdown so just pretend they are there)

Python has a similar thing called "fstrings". In python it would look like f"{x}-{y}"

There are some interesting other features of the backtick strings in JavaScript that I don't use that I won't describe here.

re: JavaScript 

@wallhackio Oh! So it's what printf does in C, and what f-strings do in Python! It's a good feature. (Though I'd still rather use printf...)

re: JavaScript 

@vaporeon_ the vaporeon will always have C brain (sea brain?)

criticizing printf() 

@wallhackio Though printf has the downside of how it's very annoying to print a value of a specific width, e.g. an uint64_t, you have to do something like printf("the uint64_t is %" PRIu64 "\n", i);, and that's really ugly

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.