Test

mail@pastecode.io avatar
unknown
javascript
3 years ago
1.1 kB
4
Indexable
Never
data.posts.map((item) => {
      if (item.repeat === null) {
        this.instaArr.push(item);
      } else {
        this.customArr.push(item);
      }
    });

    if (this.instaArr.length >= this.customArr.length) {
      this.arr1 = this.instaArr;
      this.arr2 = this.customArr;
    } else {
      this.arr1 = this.customArr;
      this.arr2 = this.instaArr;
    }

    let n = 0;
    let a = this.arr1.length + Math.floor(this.arr1.length / (this.repeat - 1));
    let b = this.repeat * this.arr2.length;

    if (a < b) {
      n = b;
    } else {
      n = a;
    }

    let index1 = 0;
    let index2 = 0;

    for (let i = 1; i <= n; i++) {
      if (i % this.repeat === 0) {
        if (index2 < this.arr2.length) {
          this.printArr[i] = this.arr2[index2];
          index2++;
        } else {
          index2 = 0;
          this.printArr[i] = this.arr2[index2];
          index2++;
        }
      } else {
        if (index1 < this.arr1.length) {
          this.printArr[i] = this.arr1[index1];
          index1++;
        } else {
          index1 = 0;
          this.printArr[i] = this.arr1[index1];
        }
      }
    }