This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Générateur asynchrone | |
async function* webservice(entity) { | |
let index = 1; | |
while (true) { | |
try { | |
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`); | |
if (!response.ok) { | |
throw new Error("Not found"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Générateur asynchrone récursif | |
async function* webservice(entity, index = 1) { | |
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`); | |
if (response.ok) { | |
yield response.json(); | |
// Yield Star (yield*) | |
// Permet de renvoyer la valeur résolue d'un générateur dans un générateur | |
// Équivalent d'applatir une imbrication de génerateur les uns dans les autres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function* webservice(entity, index = 1) { | |
const response = await fetch(`https://jsonplaceholder.typicode.com/${entity}/${index}`); | |
if (response.ok) { | |
yield response.json(); | |
yield* webservice(entity, index + 1); | |
} | |
} | |
for await (const user of webservice("users")) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cart = [ | |
["product" => "paper", "quantity" => 7, "price" => 1.26], | |
["product" => "pen", "quantity" => 2, "price" => 0.12], | |
["product" => "eraser", "quantity" => 5, "price" => 0.89] | |
]; | |
$stocks = [ | |
["product" => "paper", "quantity" => 88], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<?php | |
$students = [ | |
[ | |
"id" => 1, | |
"name" => "Amanda ANDERSSON", | |
"CC1" => 10, | |
"CC2" => 17, | |
"CC3" => 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cart = [ | |
[ | |
"product" => "paper", | |
"quantity" => 7, | |
"price" => 1.26 | |
], | |
[ | |
"product" => "pen", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<?php | |
$cart = [ | |
[ "product" => "paper", "quantity" => 7, "price" => 1.26 ], | |
[ "product" => "pen", "quantity" => 2, "price" => 0.12 ], | |
[ "product" => "eraser", "quantity" => 5, "price" => 0.89 ] | |
]; | |
$stocks = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = new XMLHttpRequest(); | |
const errorElement = document.getElementById("error"); | |
const postsElement = document.getElementById("posts"); | |
request.addEventListener("timeout", function() { | |
errorElement.innerText = "Le délai d'attente maximum est dépassé pour la requête."; | |
}); | |
request.addEventListener("error", function() { | |
errorElement.innerText = this.statusText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For these excercises : | |
// - Only use recursion (or direct recursion) | |
// - Array.prototype methods are prohibited | |
// - for, while & do while loops are prohibited | |
// - Array.prototype.length is accepted | |
/** | |
* @description Update every item of an array | |
* @param {<Type>(item: Type) => Type} update A function that will update one item | |
* @param {Array<Type>} items An array of items to update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const partial = (callback, ...initialArguments) => { | |
return (...additionalArguments) => { | |
const allArguments = [...initialArguments, ...additionalArguments]; | |
if (allArguments.length >= callback.length) { | |
return callback(...allArguments); | |
} | |
return partial(callback, ...allArguments); | |
}; |