填充双数组逻辑错误?

时间:2017-04-27 07:26:08

标签: javascript jquery arrays functional-programming

在java脚本中实现一些分页算法以便练习。 我得到了想要推入多维数组(双)的数组上的正确输出,但它只推送最终版本。我打印到控制台,这是我应该填充所有不同版本的帧。这是一个奇怪的JS与数组或什么?     //变量声明     var frameNumber = 3;     var refStringSize = 6;

var faultCount=0;
var refString = [];
var _frames=[];
var arrayOfDisplayArrays=[];

console.log("refString: "+refString);
//didnt include other functions 
//"driver"
 for(i=refStringSize;i>0;i--){
    var x = refString.shift();
    //if frames are not filled
    if(_frames.length!=frameNumber){
        if(!_includes(_frames,x)){
            _frames.push({'x':x,'checked':false});
            faultCount++;
            console.log('----')
            console.log(_frames);
            arrayOfDisplayArrays.push(_frames); 

        }   

    //if frames are filled
    }else{
        if(!_includes(_frames,x)){
        var index=getLRUIndex(_frames,refD);
        _frames[index]={'x':x,'checked':false};
        faultCount++;
        console.log('----')
        console.log(_frames);
        arrayOfDisplayArrays.push(_frames); 

        }
    }
    refD.push(x);


 }
 console.log(arrayOfDisplayArrays);

这是我的输出(忽略已选中):

    refString: 2,9,4,5,8,9
    ----
    [ { x: 2, checked: false } ]
    ----
    [ { x: 2, checked: false }, { x: 9, checked: false } ]
    ----
    [ { x: 2, checked: false },
      { x: 9, checked: false },
      { x: 4, checked: false } ]
    ----
    [ { x: 5, checked: false },
      { x: 9, checked: false },
      { x: 4, checked: false } ]
    ----
    [ { x: 5, checked: false },
      { x: 8, checked: false },
      { x: 4, checked: false } ]
    ----
    [ { x: 5, checked: false },
      { x: 8, checked: false },
      { x: 9, checked: false } ]
    ---------array of arrays----
    [ [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ],
      [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ],
      [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ],
      [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ],
      [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ],
      [ { x: 5, checked: false },
        { x: 8, checked: false },
        { x: 9, checked: false } ] ]

0 个答案:

没有答案