ruby
def middle(array)
array.length % 2 == 0 ? array[(array.length / 2) - 1] : array[array.length / 2]
end
Go to list of users who liked
Share on X(Twitter)
Share on Facebook
More than 5 years have passed since last update.
def middle(array)
array.length % 2 == 0 ? array[(array.length / 2) - 1] : array[array.length / 2]
end
Register as a new user and use Qiita more conveniently
Go to list of users who liked