var prenoms = ["Martin", "Marc", "Maxime"]
var eleves = []
for (var i = 0; i < prenoms.length; i++) {
eleves.push(prenoms[i].toUpperCase())
}
eleves.sort()
console.log(eleves) // ["MARC", "MARTIN", "MAXIME"]
var eleves = Immutable.List(["Martin", "Marc", "Maxime"])
.map(prenom => prenom.toUpperCase())
.sort()
.toArray()
console.log('first', eleves); // ["MARC", "MARTIN", "MAXIME"]
var eleves = ['Jean']
eleves.push('Marc') // Mutation
eleves // ["Jean", "Marc"]
var eleves = ['Jean']
var nouvelle_classe = [...eleves, 'Marc']
nouvelle_classe
today = moment()
/*
*
* Plein de code
*
*/
future = today.add('years', 1)
// Bugs !
today === future // true ??
today = moment()
/*
*
* Plein de code
*
*/
future = today.clone().add('years', 1)
today === future // false
class1 = [1, ..., 1 000 000]
class2 = [...class1, 'Marc']
// 2 tableaux en mémoires :(
function count_eleves () {
return "Il y a " + eleves.length + " eleves !"
}
var eleves = ['Jean', 'Marc']
count_eleves()
function count_eleves (eleves) {
return "Il y a " + eleves.length + " eleves !"
}
var eleves = ['Jean', 'Marc']
count_eleves(eleves)
function count_eleves (eleves, compteur) {
return "Il y a " + compteur(eleves) + " eleves !"
}
var eleves = ['Jean', 'Marc']
count_eleves(eleves, items => items.length + 1)
var numbers = [1, 2, 3, 4]
var multiplyBy = function (n) {
return function (item) {
return item * n
}
}
numbers.map(multiplyBy(10)) // [10, 20, 30, 40]
var numbers = [1, 2, 3, 4]
numbers.map(item => item * 10) // [10, 20, 30, 40]
numbers.filter(item => item % 2 === 0) // [2, 4]
numbers.reduce((accumulateur, item) => accumulateur + item) // 10
sont sur un bateau...