Created
September 8, 2015 19:01
-
-
Save mzabriskie/1ee9a8865d70e900f4e3 to your computer and use it in GitHub Desktop.
Calculate Net Promoter Score
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
// Expects an array of scores from 0-10 | |
// Example: nps([10, 9, 10, 4]); -> 50 | |
// See http://www.medallia.com/net-promoter-score/ | |
function nps(scores) { | |
var promoters = 0; | |
var detractors = 0; | |
for (var i=0, l=scores.length; i<l; i++) { | |
if (scores[i] >= 9) promoters++; | |
if (scores[i] <= 6) detractors++; | |
} | |
return Math.round(((promoters / l) - (detractors / l)) * 100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment