let arr = [
{
type: 'feature',
value: 'aaab',
},
{
type: 'function',
value: 'funca',
},
{
type: 'function',
value: 'funcb',
},
]
str = "#fun_longestCommonSubstr(#fun_getStrValFromList(targetUserWatchLiveAuthorZset),gamelive_comment,nonMap)",
arr = [
{
type: 'FUNCTION',
value: 'fun_longestCommonSubstr',
},
{
type: 'FUNCTION',
value: 'fun_getStrValFromList',
},
{
type: 'VARIABLE',
value: 'targetUserWatchLiveAuthorZset',
},
{
type: 'VARIABLE',
value: 'nonMap',
},
{
type: 'VARIABLE',
value: 'gamelive_comment',
}
]
function f2(arr, v) {
let n = arr.length;
while(n--) {
n && arr.splice(n, 0, v)
}
return arr;
}
function f1(arr, str, idx){
if (idx === arr.length) return [str];
let element = arr[idx]
let res = str.split(element.value).map(item => f1(arr, item, idx + 1))
console.log(111, JSON.parse(JSON.stringify(res)));
// 插入 + 数组扁平
let ar = f2(res, element);
let rt = []
ar.forEach((val, idx1) => {
if (idx1 % 2 === 0) {
if (val + '') {
rt = rt.concat(val)
}
} else {
rt.push(val)
}
});
return rt;
}
f1(arr,str,0)