Return island sizes from a string map, largest first
A map editor for a strategy game shows a “Landmasses” panel listing every island and its area. Maps are stored as arrays of strings, one string per row. Implement surveyIslands(map, options), which returns the size of every island, largest first.
surveyIslands(map, options?) // => number[]
// options: { diagonal?: boolean } (default false)
'#' character is land. Every other character ('.', '~', a space, …) is water.{ diagonal: true }, cells that touch diagonally also connect.[]) returns [].surveyIslands([
'##..#',
'#...#',
'..#..',
'.....',
'##.##',
]);
// => [3, 2, 2, 2, 1]
surveyIslands(['#.#', '.#.', '#.#']);
// => [1, 1, 1, 1, 1]
surveyIslands(['#.#', '.#.', '#.#'], { diagonal: true });
// => [5]
surveyIslands(['###', '#', '~~#~', '...#']);
// => [4, 1, 1] (row 1 has one cell; the rest of it is water)
surveyIslands(['....']);
// => []