Last active
March 31, 2017 15:58
-
-
Save djom202/97abd6332d59269c26d4df4677aa7d44 to your computer and use it in GitHub Desktop.
Creating a distribution from an options number and an answers count to answer a Qrvey
This file contains hidden or 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
| function dist(num, answersCount){ | |
| var perc = Array.apply(null, { length: num }).map(function() { | |
| return parseInt(answersCount / num); | |
| }), | |
| rest = answersCount - (parseInt(answersCount / num) * num); | |
| perc[0] += rest; // for when is a only one result we always the first position. | |
| return { | |
| 'perc': perc, | |
| 'answersCount': answersCount | |
| }; | |
| }; | |
| var result = dist(7, 200); | |
| console.log('last result', result); | |
| // "last result" Object { | |
| // answersCount: 200, | |
| // perc: [32, 28, 28, 28, 28, 28, 28] | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment