Closed dylandy closed 7 years ago
Good idea. It will return a Daru::Vector
incase of multiple values.
Example:
require 'daru'
v = Daru::Vector.new([1,2,3,4,4,5,5])
v.mode #=> Daru::Vector with [4,5]
I've implemented this to return a Daru::Vector
as suggested but would it not be better to return an array of 1 or more values so that the return type is always consistent and doesn't need to be checked for on the calling side?
@db579 Let's postpone this question or put it in a separate GitHub issue for discussion (I believe, we have several places with the same concept). In fact, the idiom is not unusual for Ruby:
array = [1,2,3]
array[1] # => 2 # single value
array[1..2] # => [2, 3] # array of values
Though, in this case user explicitly requires one value or range of values, unlike the #mode
.
I found that mode function can only return a single value even when the input vector has multiple modes. Is it a better choice for return a list of mode values rather than return a single value ?