I am new to JavaScript, and I move on to the task when I have to randomly distribute an input value between 12 loads. The other side is that each element of the array cannot differ from the next by more than one.
so, for example, if I have 30, I need to distribute this amount between 12 camels. I still wrote the code below, but I am using TextPad on request. I am not sure how to print the result on the same line.
var amount = 30;
var camels = [0,0,0,0,0,0,0,0,0,0,0,0]
var div = amount/12;
var mod = amount%12;
var x = mod / 12;
for(i=0;i<camels.length;i++){
WScript.echo(camels[i] + "|" + Math.floor(div) + "|" + mod + "|" + x)
}
comment if you need more information, thanks
user2982634
source
share