Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fegoa89/average
Find the arithmethic mean/mode/median of an array of numbers .
https://github.com/fegoa89/average
average ruby
Last synced: 10 days ago
JSON representation
Find the arithmethic mean/mode/median of an array of numbers .
- Host: GitHub
- URL: https://github.com/fegoa89/average
- Owner: fegoa89
- License: mit
- Created: 2015-02-26T19:16:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T07:57:48.000Z (about 6 years ago)
- Last Synced: 2024-08-10T02:53:49.729Z (3 months ago)
- Topics: average, ruby
- Language: Ruby
- Homepage:
- Size: 32.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Build Status](https://semaphoreci.com/api/v1/projects/fd96a25e-c843-44ff-8c43-1da486ca03a6/425376/badge.svg)](https://semaphoreci.com/fegoa89/average)
# Average
Simple gem to calculate mean, median and mode from an array.
## Installation
Add this line to your application's Gemfile:
gem 'average'
And then execute:
$ bundle
Or install it yourself as:
$ gem install average
## Usage
Get Median
$ [3, 4, 5, 2, 3, 1].mean
$ 3.0Get Mode
$ [2,4,6,14,21,24,229,24,24,39].mode
$ 24It gives back an array due that could be possible to have more than one mode in a array
$ [1, 2, 2, 2, 3, 3, 7, 7, 7, 9].mode
$ [2, 7]But if you want to have only a unique mode, you can use 'unique_mode' method (Only for Ruby versions bigger than 1.8.7 -> http://apidock.com/ruby/v1_8_7_72/Enumerable/max_by).
$ [1, 2, 2, 2, 3, 3, 7, 7, 7, 9].unique_mode
$ 2Get Median
$ [3,4,5].median
$ 4
All methods described aboved can handle an array of integers, floats, strings or a mixed array with all of them
$ [3, "4", 5, 2.0, 3, "1.0"].mean
$ 3.0## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request