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
let words = ["Beau", "Ange", "Ananas", "Ballon"]; | |
function forEach(array, fx) { | |
for (var i = 0; i < array.length; i++)//for of | |
fx(array[i], i , array); | |
} | |
console.log('----- UpperCase ------'); | |
let upperCase = function(word,i,t){ | |
t[i]= t[i].toUpperCase(); | |
} | |
forEach(words,upperCase); | |
console.log('----- start A -------'); | |
//afficher true si commence par A | |
let beginWithA = function(word,i,t){ | |
t[i]= /^A/.test(word)?"True":"False" | |
} | |
forEach(words,beginWithA); | |
words = ["Beau", "Ange", "Ananas", "Ballon"]; | |
let includeE = function(word,i,t){ | |
t[i]= /e/.test(word)?"e":"-" | |
} | |
forEach(words,includeE); | |
words = ["Beau", "Ange", "Ananas", "Ballon"]; | |
let replaceE = function(word,i,t){ | |
t[i] = word.replace('e', '--e--') | |
} | |
forEach(words,replaceE); | |
const dom = ["data-number","data-operator"] | |
const dashToCamelCase = ( str,i,t ) => { | |
t[i] = str.replace(/-./g, function ($) { return $[1].toUpperCase(); }); | |
} | |
dom.forEach(dashToCamelCase); |
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
let words = ["Beau", "Ange", "Ananas", "Ballon"]; | |
console.log('----- Affiche ------'); | |
//afficher les mots | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i]) | |
} | |
console.log('----- nb de chars ------'); | |
//afficher la taille | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i].length) | |
} | |
console.log('----- UpperCase ------'); | |
//afficher en majuscule | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i].toUpperCase()) | |
} | |
console.log('----- include g ----'); | |
//afficher si true la lettre "g" | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i].includes("g")?"True":"False"); | |
} | |
console.log('----- include b ----'); | |
//afficher si true la lettre "b" | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i].toLowerCase().includes("b")?"True":"False"); | |
} | |
console.log('----- start A -------'); | |
//afficher si true commence par A | |
for (let i=0; i<words.length; i++){ | |
console.log(/^A/.test(words[i])?"True":"False") | |
} | |
words = ["data-number","data-operator"] | |
//affiche dashToCamelCase | |
for (let i=0; i<words.length; i++){ | |
console.log(words[i].replace(/-./g, function ($) { return $[1].toUpperCase()})); | |
} |