javascript中等分布式百分比计算

时间:2015-07-26 23:44:15

标签: javascript percentage

function percentify(num, param){
    for(var i=(param==true?0:1),array=[]; i<=num; i++)
        array.push( (param==true?i:1)*100/num )
    return array
}

console.log( percentify(7,true)[5] );

1 个答案:

答案 0 :(得分:1)

猜测解决方案..解释&#34; 7分成7个部分,每个部分代表100和#34的百分比数量;

class Pawn{ 
       private boolean hasMovedAlready=false;
       ...
       public Pawn copy(){
          return new Pawn(hasMovedAlready, ...);
}

输出

function eqPercentify(num){
    for(var i=1,result=[]; i<=num; i++){
        result.push(i * 100 / num);
    }
    return result;
}

console.log( eqPercentify(7) );