0
Students
This is an advanced version of the Sea Battle challenge.
solution.js
Implement and export as default a function that takes the battlefield as a square two-dimensional array of zeros and ones. Zero is an empty cell, one is a part of the ship. The function should return the number of ships on the battlefield.
Unlike the classic game of "Sea Battle", in this version, the ships can be placed in the shape of the "г" figure and the "snake".
calcShipsCount([]); // 0
calcShipsCount([
[1, 0, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[1, 1, 1, 0, 0, 1],
[0, 0, 0, 0, 1, 1],
[0, 1, 0, 0, 1, 0],
]); // 5
Tips
- If necessary, use the functions from the lodash library
- The tests contain a case with square 4-deck ships on the field. Uncomment it if you want to make the task even more tricky
For full access to the challenge you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.