Skip to content

Instantly share code, notes, and snippets.

@servidorv
Created November 7, 2012 20:14
Show Gist options
  • Save servidorv/4034100 to your computer and use it in GitHub Desktop.
Save servidorv/4034100 to your computer and use it in GitHub Desktop.
returning the same value
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