Skip to content
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

fix mode is returning an Array instead of Set if count of modes is same as count of numbers in the parameter passed to mode (issue #16) #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function mode(vals) {
// multi-modal
if (rank.length == vals.length) {
// all values are modes
return vals
return new Set(vals)
}
var modes = new Set([mode])
var modeCount = dist[mode]
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ test("mode", function (t) {

t.deepEquals(mode([1, 2, 2, 2, 3, 14]), 2, "mode works")

t.deepEquals(mode([1, 2]), new Set([1, 2]), "all values are modes works")

t.deepEquals(mode([1, 2, 3, 4]), new Set([1, 2, 3, 4]), "all values are modes works")

t.deepEquals(mode([1, 1, 7, 5, 5, 8, 7]), new Set([1, 5, 7]), "multi-modal works")

t.deepEquals(mode([1, 1, 7, 5, 5, 8, 7]), new Set([1, 7, 5]), "multi-modal works and order doesn't matter (yay Set)")
Expand Down