Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_Problems_/max-consecutive-1s/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ function findMaxConsecutive1s(arr) {
if (count > max) max = count;
return max;
}

module.exports = { findMaxConsecutive1s };
20 changes: 20 additions & 0 deletions src/_Problems_/max-consecutive-1s/max-consecutive-1s.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { findMaxConsecutive1s } = require(".");

describe("Find maximum numbers of consecutive 1s", () => {
it("returns 1 if there is only one number 1", () => {
expect(findMaxConsecutive1s([1])).toEqual(1);
});

it("return the appropriate count for a large array", () => {
const largeArray = [0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1];
expect(findMaxConsecutive1s(largeArray)).toEqual(5);
});

it("returns count 0 if there is no number 1", () => {
expect(findMaxConsecutive1s([0, 2, 3, 9, 0])).toEqual(0);
});

it("does NOT count negative 1s", () => {
expect(findMaxConsecutive1s([1, 1, 0, -1, -1, -1])).toEqual(2);
});
});