Skip to content

Commit 8d44461

Browse files
author
Mrinal Chauhan
committed
feat : added find majority element in array using Moore's Voting Algorithm test file
1 parent a7928f5 commit 8d44461

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {MooreVotingAlgorithm} from "../MooreVotingAlgorithm";
2+
describe('Moore Voting Algorithm', () => {
3+
it.each([
4+
[[1, 1, 2, 1, 3, 1, 1], 1], // Majority element 1
5+
[[1, 2, 3, 4], null], // No majority element
6+
[[2, 2, 2, 2, 5, 5, 5, 2], 2], // Majority element 2
7+
[[], null], // Empty array, no majority
8+
[[3], 3] // Single element, it's the majority
9+
])('returns %j when given %j', (array, expected) => {
10+
expect(MooreVotingAlgorithm(array)).toEqual(expected);
11+
});
12+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy