Les modules se r茅partissent en trois cat茅gories :
dupontL3
馃洨️Analysez ce code !
const arr2 = [1, 2, 3];
const arr1 = [4, 5, 6, 7, 8];
const [small, large] = arr1.length < arr2.length
? [arr1, arr2]
: [arr2, arr1];
console.log(small == arr2); // [1, 2, 3] [4, 5, 6, 7, 8]
const mapToppings = new Map([
["queen", ["馃惙", "馃崉", "馃崊", "馃"]],
["cheese", ["馃", "馃崊"]],
["oriental", ["馃崊", "馃悜", "馃崉", "馃尪"]],
["royal", ["馃崊", "馃尩"]],
]);
const order1 = [
{ name: "queen", ingredients: mapToppings.get("queen") },
{ name: "cheese", ingredients: mapToppings.get("cheese") },
{ name: "oriental", ingredients: mapToppings.get("oriental") },
{ name: "royal", ingredients: mapToppings.get("royal") },
];
const order2 = [
{ name: "queen-promo", ingredients: mapToppings.get("queen") },
{ name: "royal-promo", ingredients: mapToppings.get("royal") },
];
function intersectionBy(a, b, keyFn) {
const setB = new Set(b.map(keyFn));
return a.filter((item) => setB.has(keyFn(item)));
}
const common = intersectionBy(order1,
order2,
(pizza) => pizza.ingredients);
console.log(common);
// [{ name: "queen", ingredients: [...] }, { name: "royal", ingredients: [...] }]
Inscription 脿 :
Commentaires (Atom)