-
Notifications
You must be signed in to change notification settings - Fork 560
Expand file tree
/
Copy pathex6.js
More file actions
38 lines (31 loc) · 1.2 KB
/
ex6.js
File metadata and controls
38 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Array.prototype.filter - Exercice 6
Ecrire une fonction filterOffensiveComments, qui attend deux paramètres, tous deux
des tableaux de chaînes de caractères :
1. des commentaires sur un fil d'actualité ou une vidéo.
2. une liste de mots "grossiers" ou "offensifs" à bannir
La fonction doit éliminer les commentaires contenant au moins un des mots "bannis".
Exemple d'entrée:
1. des commentaires (on est resté soft pour ne pas heurter les oreilles chastes)
[
"Very useful tutorial, thank you so much!",
"React is not a damn framework, it's a LIBRARY"
"Why you put bloody kitten pictures in a tech tutorial is beyond me!",
"Which one is better, React or Angular?",
'There is no "better", it depends on your use case, DAMN YOU'
]
2. mots à bannir: ['bloody', 'damn']
Sortie attendue:
[
"Very useful tutorial, thank you so much!",
"Which one is better, React or Angular?",
]
*/
function filterOffensiveComments(comments, bannedWords) {
for (let i = 0; i<bannedWords.length; i++){
const carotte = comments.filter(comment => comment.toLowerCase().includes(bannedWords[i]) === false)
comments = carotte
}
return comments
}
// Ne pas modifier l'export
module.exports = filterOffensiveComments;