Voici à quoi ressemble l'aggregation dans une base de données !
const products = [
const groupBy = (arr, key) =>
Voici à quoi ressemble l'aggregation dans une base de données !
const products = [
const groupBy = (arr, key) =>
const dir = films.reduce( (acc, cur) => {
acc[cur.director] = [ ... (acc[cur.director] || [] ), cur.title ];
return acc;
}, {});
html | "<div> <h1> {{question}} </h1> <ul> <li>{{choice1}}</li> <li>{{choice2}}</li> <li>{{choice3}}</li> <li>{{choice4}}</li> </ul> </div>" |
randomChoise | 2 |
newCode | "<div> <h1> {{question}} </h1> <ul> <li>{{choice1}}</li> <li class='selected'>{{choice2}}</li> <li>{{choice3}}</li> <li>{{choice4}}</li> </ul> </div>" |
const html = `<div> <h1> {{question}} </h1> | |
<ul> | |
<li>{{choice1}}</li> | |
<li>{{choice2}}</li> | |
<li>{{choice3}}</li> | |
<li>{{choice4}}</li> | |
</ul> | |
</div>`; | |
const randomChoise = (html, tagName, pos) => { | |
const regExp = new RegExp(`<${tagName}`, 'g'); | |
let nbMatch = 0; | |
let newHTML = html.replace(regExp, function (match) { | |
if (nbMatch++ == pos) { | |
return `${match} class='selected'` | |
} else { | |
return match; | |
} | |
}) | |
return newHTML; | |
} | |
const newCode = randomChoise(html, 'li', 2); | |
console.log(newCode) |
https://github.com/dupontdenis/Jest-test1.git
localStorage.setItem("saveTab",[1,2,3])
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<script src="random-words.js" defer></script> | |
</head> | |
<body> | |
<h1>random word</h1> | |
<ul id="list"></ul> | |
</body> | |
</html> |
//UI | |
const list = document.getElementById('list'); | |
//random words | |
const load = async () => { | |
const sortable = JSON.parse(localStorage.getItem("words")) | |
if (!sortable) { | |
const data = await fetch("https://random-word-api.herokuapp.com/word?number=20"); | |
const words = await data.json(); | |
const alphabetical = words.reduce((a, x) => { | |
if (!a[x[0]]) a[x[0]] = []; | |
a[x[0]].push(x); | |
return a; | |
}, {}); | |
// console.log(alphabetical) | |
const sortable = Object.fromEntries( | |
Object.entries(alphabetical).sort(([a,], [b,]) => { | |
if (a > b) { | |
return -1 | |
} else { | |
return 1 | |
} | |
}) | |
); | |
localStorage.setItem("words", JSON.stringify(sortable)); | |
return sortable; | |
} else { | |
return sortable; | |
} | |
} | |
// UI | |
(async () => { | |
const words = await load(); | |
Object.entries(words).forEach(([letter, words]) => { | |
// console.log(letter, words) | |
const tempLi = document.createElement('li') | |
, tempUl = document.createElement('ul'); | |
words.forEach((word) => tempUl.insertAdjacentHTML('afterbegin', `<li> ${word} </li>`)) | |
tempLi.insertAdjacentElement('beforeend', tempUl) | |
.insertAdjacentText('beforebegin', `${letter}`) | |
document | |
.querySelector("#list") | |
.insertAdjacentElement('afterbegin', tempLi) | |
}) | |
})() |
RegExp: \d(?=(\d{3})+\.)
Un nombre suivi de 3 nombres (une ou plusieurs fois) et un point sans les consommer (?= ).
Remplacement: $&
Correspond au chiffre \d qui correspond.
Match 1 | 0-1 | 1 |
Group 1 | 4-7 | 332 |
Match 2 | 3-4 | 5 |
Group 1 | 4-7 | 332 |
https://random-word-api.herokuapp.com/word?number=3&length=-1
https://random-word-api.herokuapp.com
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<script type="module" defer src="./script.js"></script> | |
</head> | |
<body> | |
click and see the console | |
</body> | |
</html> |
export default function printModule(){ | |
console.log("from module") | |
} | |
export function cl(){ | |
console.log("top") | |
} |
document.addEventListener("click", async () => { | |
const {default: printModule, cl } = await import("./module.js"); | |
printModule(); | |
cl(); | |
console.log("from script") | |
}); |
console.log(state)
L'affichage montre qu'une fois protégé on ne peut pas modifier l'état.
{ account: 'top' }
{ account: 2 }
{ account: 3 }
{ account: 3 }
const obj = { "un": 1, deux: 2, trois: 3 };
const tab = Object.entries(obj);
console.log(tab) //
const obj2 = Object.fromEntries(
Object.entries(obj)
.map(([ key, val ]) => [ `${key}*2`, val * 2 ])
);
console.log(obj2);
https://codepen.io/dupontcodepen/pen/abEaYeQ
let value = 610;