Created
January 6, 2015 11:38
-
-
Save lylo/bc2a9bb62402b45a7c55 to your computer and use it in GitHub Desktop.
NPS calc in Ruby
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
class NpsCalculator | |
def nps(scores) | |
(promotor_share(scores) - detractor_share(scores)).round | |
end | |
private | |
def promotor_share(scores) | |
scores.count {|score| score > 8} / scores.count.to_f * 100 | |
end | |
def detractor_share(scores) | |
scores.count {|score| score < 7} / scores.count.to_f * 100 | |
end | |
end | |
# Usage example | |
# scores = [9,5,10,6,4,5,7,8,8,9,6] | |
# puts NpsCalculator.new.nps scores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment