场景一:在信息流中插入广告
已有一个用于展示的数组(为空),获取到需要展示的内容和广告,加入到展示数组中。
let showList = [],
ctnList = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2'],
adList = ['A', 'B', 'C', 'D'];
const pushAds = (ctnList, adList) => {
let ret = [];
adList.forEach((item, index) => {
ret.push(ctnList[index * 2]);
ret.push(ctnList[index * 2 + 1]);
ret.push(item);
});
return ret;
});
showList.concat(pushAds(ctnList, adList));