Created
November 7, 2012 20:14
-
-
Save servidorv/4034100 to your computer and use it in GitHub Desktop.
returning the same value
This file contains 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
best, worst = calculate_best_worst(key_mapped_values) | |
secbest, secworst = calculate_sec_best_worst(key_mapped_values.clone, best, worst) | |
{'best' => best, 'secbest' => secbest, 'worst' => worst, 'secworst' => secworst} | |
def calculate_best_worst(hash) | |
best = hash.max {|a,b| a[1] <=> b[1]} || [] | |
worst = hash.min {|a,b| a[1] <=> b[1]} || [] | |
return best, worst | |
end | |
def calculate_sec_best_worst(hash, best, worst) | |
hash.delete(best) | |
hash.delete(worst) | |
secbest = hash.max {|a,b| a[1] <=> b[1]} || [] | |
secworst = hash.min {|a,b| a[1] <=> b[1]} || [] | |
return secbest, secworst | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment