Published
Edited
Mar 19, 2020
Insert cell
Insert cell
fruits = ([
{name: 'Pomme', num: 5},
{name: 'Pêche', num: 3 },
{name: 'Banane', num: 6}
])
Insert cell
Insert cell
fruits.map(() => `Rien à voir`)
Insert cell
Insert cell
fruits.map(fruit => `J'ai ${fruit.num} ${fruit.name}s`)
Insert cell
Insert cell
fruits.map((fruit, i) => `L'index est ${i}`)
Insert cell
Insert cell
fruits.map((fruit, i) => `La ${fruit.name} est à l'index ${i}`)
Insert cell
Insert cell
commenceParP = fruit => fruit.name.startsWith('P')
Insert cell
Insert cell
fruits.map(fruit => `${fruit.name} commence par P: ${commenceParP(fruit)}`)
Insert cell
Insert cell
fruits.filter(commenceParP)
Insert cell
Insert cell
fruits.filter((fruit, i) => i < 2)
Insert cell
Insert cell
fruits.find(commenceParP)
Insert cell
Insert cell
commenceParZ = fruit => fruit.name.startsWith('Z')
Insert cell
fruits.find(commenceParZ)
Insert cell
Insert cell
chiffres = [6, 3, 5, 8]
Insert cell
Insert cell
sum = (resultat, chiffre) => resultat + chiffre
Insert cell
Insert cell
chiffres.reduce(sum, 0)
Insert cell
Insert cell
fruits.reduce((resultat, d) => resultat + d.num, 0)
Insert cell
Insert cell
VALEUR_DE_DEPART = ({ p: [], autres: [] })
Insert cell
Insert cell
separerLesFruitsQuiCommencentParP = ({ p, autres }, d) =>
// la fonction commenceParP retourne "true" ou "false"
commenceParP(d)
// si "true", ajouter "d" à la liste "p"
? { p: [...p, d], autres }
// si "false", ajouter "d" à la liste "autres"
: { p, autres: [...autres, d] }
Insert cell
fruits.reduce(separerLesFruitsQuiCommencentParP, VALEUR_DE_DEPART)
Insert cell
Insert cell
[1, 2, 3].includes(2)
Insert cell
[1, 2, 3].includes(4)
Insert cell
Insert cell
['c', 'd', 'b', 'a'].sort()
Insert cell
Insert cell
[12, 2, 1, 23].sort()
Insert cell
Insert cell
[12, 2, 1, 23].sort((a, b) => a > b ? 1 : -1)
Insert cell
[12, 2, 1, 23].sort((a, b) => a > b ? -1 : 1)
Insert cell
fruits.sort((a, b) => a.num > b.num ? -1 : 1)
Insert cell
Insert cell
fruits.map(d => d.name).join('----')
Insert cell
fruits.map(d => d.name).join('\n')
Insert cell
Insert cell
[1, 2, 3].join(' + ')
Insert cell
Insert cell
fruits.join('.')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more