Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d44461

Browse files
author
Mrinal Chauhan
committed
feat : added find majority element in array using Moore's Voting Algorithm test file
1 parenta7928f5 commit8d44461

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)

[8]ページ先頭

©2009-2025 Movatter.jp