[Coding] Islands count.
Given a 5x5 matrix where 1 represents a land and 0 represent a water.
Write a function that will count the islands in the given matrix.
What's an island? If 1 has an adjacent 1 in any direction (N, NE, E, SE, S, SW, W, NW) it forms an island.
-- [code javascript] ---
var m = [
[1, 1, 0, 0, 0],
[0, 1, 0, 0, 1],
[1, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[1, 0, 1, 0, 1]
];
function islandsCount(map) {
// your code here
return 0;
}
console.log("Number of islands: ", islandsCount(m));
-- [end code javascript] ---
Expected count is 5.