Return a specific digit number, based on another number
I want a function where I can input an array, with arbitrary min and max
numbers.....and have the output add up all the numbers in the array, but
then recursively whittle it down to fit within the min max range.
Example
function getNumber(array, min, max){
var n =0;
for(var i=0;i<array.length;i++){
n += array[i];
}
// Lets pretend the result of n is now 182;
//
// I want to do something here, that will check the min and max numbers
// and make this number fit.
// IE if min = 0, and max=1;
// I would want to return 0.182;
// If min = 5000; max = 20,000
// I would want n to be 18200
// etc...
}
I know this is quite a simple task, but I can't for the life of me think
how to do it.
No comments:
Post a Comment