Convertir un tableau en pourcentage le plus rapidement possible
Bonjour,
à cause d'une fonction SetTimeout contraignante je dois réaliser une conversion de tableau en pourcentage dans un temp record :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| function percent(array)
{
var i, max=0;
var newarray = new Array();
for (i=0; i<array.length; i++)
max = max+array[i];
for (i=0; i<array.length; i++)
newarray[i] = Math.floor((array[i]/ max) * 100 );
return newarray;
}
$grawdata=percent($grawdata); |
comment rendre le temps d'execution de ce code le plus court possible.