npm.io
1.0.3 • Published 5 years ago

majority

Licence
MIT
Version
1.0.3
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
1

majority

total downloads of majority majority's License latest version of majority

A two-bit library to get the most popular value.

(new Majority(1, 1, 2, 2, 2, 3, 3)).value()
// 2

const majority = new Majority()

console.log(majority.value('foo'))
// foo

for (let i = 0; i < 5; ++i) majority.feed('Trump')

console.log(majority.value())
// Trump

for (let i = 0; i < 10; ++i) majority.feed('Biden')

for (let i = 0; i < 6; ++i) majority.feed('Hilary')

console.log(majority.value())
// Biden