Skip to content

Instantly share code, notes, and snippets.

@mzabriskie
Created September 8, 2015 19:01
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzabriskie/1ee9a8865d70e900f4e3 to your computer and use it in GitHub Desktop.
Save mzabriskie/1ee9a8865d70e900f4e3 to your computer and use it in GitHub Desktop.
Calculate Net Promoter Score
// 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