Skip to content

Moore's Voting Algorithm - Boyer-Moore Majority Voting Algorithm #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat : added find majority element in array using Moore's Voting Algo…
…rithm test file
  • Loading branch information
Mrinal Chauhan committed Oct 23, 2024
commit 8d44461767b586972aad70d643fe6d4e8783f52a
12 changes: 12 additions & 0 deletions Data-Structures/Array/test/MooreVotingAlgorithm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {MooreVotingAlgorithm} from "../MooreVotingAlgorithm";
describe('Moore Voting Algorithm', () => {
it.each([
[[1, 1, 2, 1, 3, 1, 1], 1], // Majority element 1
[[1, 2, 3, 4], null], // No majority element
[[2, 2, 2, 2, 5, 5, 5, 2], 2], // Majority element 2
[[], null], // Empty array, no majority
[[3], 3] // Single element, it's the majority
])('returns %j when given %j', (array, expected) => {
expect(MooreVotingAlgorithm(array)).toEqual(expected);
});
});
Loading
Oops, something went wrong.