Last active
December 11, 2015 14:09
-
-
Save nasospsa/4612417 to your computer and use it in GitHub Desktop.
Calculate the value based on percent
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
var randomValues= [33, 56, 29, 67, 96, 58, 72, 88, 92, 61, 19, 100, 47, 96, 93, 16, 68, 9, 6, 41, 9, 95, 69, 89, 68, 22, 52, 28, 48, 76, 80, 35, 29, 18, 60, 95, 5, 46, 98, 55, 94, 70, 36, 94, 97, 38, 23, 98, 58, 61, 93, 55, 30, 86, 92, 74, 64, 48, 70, 69, 27, 2, 76, 52, 27, 100, 1, 23, 86, 3, 66, 63, 59, 35, 77, 75, 93, 76, 58, 32, 15, 51, 17, 67, 99, 83, 79, 67, 76, 71, 3, 31, 79, 25, 5, 66, 14, 7, 96, 48, 65, 93, 67, 9, 52, 92, 24, 73, 47, 78, 21, 48, 26, 58, 34, 55, 12, 25, 3, 62, 60, 40, 67, 73, 100, 94, 89, 96, 35, 85, 29, 13, 61, 83, 52, 75, 30, 83, 90, 60, 67, 21, 2, 54, 52, 48, 45, 26, 80, 100, 30, 6, 85, 81, 13, 84, 22, 14, 16, 98, 7, 34, 99, 86, 57, 10, 17, 98, 59, 33, 17, 4, 80, 93, 73, 92, 12, 17, 94, 1, 97, 37, 67, 35, 15, 13, 13, 82, 21, 5, 92, 52, 46, 57, 55, 34, 98, 47, 30, 93, 11, 34, 68, 28, 89, 73, 34, 79, 96, 7, 50, 98, 44, 4, 15, 89, 39, 47, 89, 86, 8, 34, 33, 19, 57, 73, 22, 70, 92, 72, 26, 21, 88, 53, 33, 29, 48, 1, 7, 75, 50, 99, 70, 86, 40, 57, 71, 21, 55, 89, 89, 3, 36, 67, 30, 44, 27, 95, 93, 77, 41, 40, 2, 85, 63, 24, 30, 15, 18, 59, 32, 59, 55, 66, 25, 54, 68, 54, 83, 96, 83, 35, 67, 1, 75, 74, 27, 29, 62, 24, 28, 44, 73, 89, 75, 2, 12, 47, 47, 42, 88, 24, 89, 19, 14, 63, 61, 13, 3, 18, 36, 54, 45, 38, 61, 7, 42, 12, 53, 48, 83, 42, 1, 25, 23, 33, 82, 24, 16, 100, 44, 100, 67, 28, 75, 14, 44, 88, 75, 67, 30, 43, 76, 22, 38, 10, 48, 7, 46, 40]; | |
var calc = function (arr, percent) { | |
var arr = arr.sort(function (a,b){ | |
return a-b; | |
}), n = arr.length * (percent/100); | |
console.log(arr); | |
var m1 = arr[Math.floor(n)] * (1 - (n%1)); | |
var m2 = arr[Math.ceil(n)] * (n%1); | |
return m1+m2; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment