riverSizes javascript
const riverSizes = input => {
let results = [];
input.forEach((row, y) => {
row.forEach((cell, x) => {
if (input[y][x] === 1) {
results.push(checkAdjacent(x, y, input));
}
});
});
return results;
};const checkAdjacent = (x, y, input) => {
input[y][x] = 0; // mark cell as visited
let size = 1;
[[x + 1, y], [x, y + 1], [x - 1, y], [x, y - 1]].forEach(([i, j]) => {
// make sure we don't access a row that doesn't exist
// then check to see if we have a river
if (input[j] && input[j][i]) {
size += checkAdjacent(i, j, input);
}
});
return size;
};
Also in JavaScript:
- ejs-multiselect
- How to check if a member has a role discord.js
- javascript date format mm/dd/yyyy
- ngingx proxy express get real ip
- react spring
- chartjs min
- how the map function works javascript
- javascript date calculations ignore weekends
- jquery select self and siblings
- js or operator
- mock api inside react component jest async
- how to push string into array in javascript
- javascript select multiple values
- javascript fetch json
- angular redirect to external url
- js go to page
- how to hide api key in react app
- javascript convert number to spreadsheet column
- biden trump javascript real time election
- javascript write to text file
- loop async javascript
- get last char javascript
- how to format json file in vs code
- signup form in angular 9