Last active
December 23, 2015 13:59
-
-
Save abacha/6645699 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def reduce(arr, amount) | |
| sample = [] | |
| ratio = (arr.count / amount).floor | |
| while sample.count < amount | |
| index = sample.count | |
| inf = index * ratio | |
| sup = (index + 1) * ratio - 1.0 | |
| sum = arr[inf..sup].reduce(:+) | |
| sample << sum / sup - inf + 1.0 | |
| end | |
| sample | |
| end |
Author
abacha
commented
Sep 21, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment