https://github.com/dupontdenis/filmsGhibli_Vanilla.git
Projet
Souriez : projet
Clonez https://github.com/dupontdenis/takepicture.git
Lancez dans un terminal le serveur avec la commande :
node app
Dans votre navigateur allez http://localhost:3000/
🛩️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: [...] }]
Objectif : comprendre ce code
- async function* getLines() {
- const data = [
- "# Commentaire ignoré",
- "Ligne utile 1",
- "Ligne utile 2",
- "# Autre commentaire",
- "STOP",
- "Ligne après STOP",
- ];
- for (const line of data) {
- await new Promise((resolve) => setTimeout(resolve, 100)); // simule un délai
- yield line;
- }
- }
- async function processUntilStop(lines) {
- for await (const line of lines) {
- if (line === "STOP") break;
- if (line.startsWith("#")) continue;
- console.log(`Traitement : ${line}`);
- }
- console.log("🔚 Fin du traitement.");
- }
- processUntilStop(getLines());
Asynchrone 🥷🏼
Introduction
Cours
Callback, promesses et Async/Await
BD (callback)
TD
🚀Asynchrone dans votre navigateur (es6)
Inscription à :
Commentaires (Atom)
