3 回答

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
var a1 = [
{text:"你"},
{text:"好"}
];
var b1 = [
{text:"你"},
{text:"好"}
];
var a2 = [
{text:"你"},
{text:"好"}
];
var b2 = [
{text:"你"},
{text:"們"}
];
function fn(a,b){
return a.every(function(item,index){
return item.text == b[index].text;
})
}
console.log(fn(a1,b1),fn(a2,b2));

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
function fn(a, b) => {
let mapA = {};
let mapB = {};
a.forEach(item => {
if(mapA[item.text]) {
mapA[item.text] += 1;
} else {
mapA[item.text] = 1;
}
});
b.forEach(item => {
if(mapB[item.text]) {
mapB[item.text] += 1;
} else {
mapB[item.text] = 1;
}
});
return Object.keys(mapA).every(key => {
return (mapB[key] && mapA[key] == mapB[key]);
})
}

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊
function fn(a,b){
a = a.length==0?"":a.map(i=>i.text);
b = b.length==0?"":b.map(i=>i.text);
a.sort();b.sort;
return a.join("") === b.join("")
}
fn([{text:"你"},{text:"好"},{text:"啊"}],[{text:"你"},{text:"啊"},{text:"好"}]);//true
添加回答
舉報(bào)