structy-logo
JavaScriptnodelogo
Course Contents
Layout 1
Prompt
Editor
Terminal
sign in
problem
approach
walkthrough
solution
add to favoritessettings

island count

Write a function, islandCount, that takes in a grid containing Ws and Ls. W represents water and L represents land. The function should return the number of islands on the grid. An island is a vertically or horizontally connected region of land.

test_00
const grid = [
['W', 'L', 'W', 'W', 'W'],
['W', 'L', 'W', 'W', 'W'],
['W', 'W', 'W', 'L', 'W'],
['W', 'W', 'L', 'L', 'W'],
['L', 'W', 'W', 'L', 'L'],
['L', 'L', 'W', 'W', 'W'],
];

islandCount(grid); // -> 3
test_01
const grid = [
['L', 'W', 'W', 'L', 'W'],
['L', 'W', 'W', 'L', 'L'],
['W', 'L', 'W', 'L', 'W'],
['W', 'W', 'W', 'W', 'W'],
['W', 'W', 'L', 'L', 'L'],
];

islandCount(grid); // -> 4
test_02
const grid = [
['L', 'L', 'L'],
['L', 'L', 'L'],
['L', 'L', 'L'],
];

islandCount(grid); // -> 1
test_03
const grid = [
['W', 'W'],
['W', 'W'],
['W', 'W'],
];

islandCount(grid); // -> 0
terminal
settings
[guest]$ 
editor — island-count.js
reset codesettings
const islandCount = (grid) => {
// todo
};

module.exports = {
islandCount,
};

saved