From 192499943243114e80b283098ca442a25131abd5 Mon Sep 17 00:00:00 2001 From: Marot <48023487+cevious77@users.noreply.github.com> Date: Tue, 26 Mar 2019 17:25:06 +0100 Subject: [PATCH 1/2] fini fini --- filter-map/ex1.js | 3 +++ filter-map/ex2.js | 5 +++++ filter/ex1.js | 1 + filter/ex2.js | 3 ++- filter/ex3.js | 4 +++- filter/ex4.js | 4 ++++ filter/ex5.js | 1 + filter/ex6.js | 5 +++++ map/ex1.js | 18 ++++++++++++++++++ map/ex2.js | 11 +++++++++++ map/ex3.js | 10 ++++++++++ map/ex4.js | 8 ++++++++ map/ex5.js | 15 +++++++++++++++ 13 files changed, 86 insertions(+), 2 deletions(-) diff --git a/filter-map/ex1.js b/filter-map/ex1.js index ef95fa93..04c42dee 100644 --- a/filter-map/ex1.js +++ b/filter-map/ex1.js @@ -23,6 +23,9 @@ Sortie attendue: */ function getJedisNames(characters) { +let padawan = characters.filter(char => char.side === 'light') +return padawan.map(jedi => {return jedi.name}) + } module.exports = getJedisNames; diff --git a/filter-map/ex2.js b/filter-map/ex2.js index 9a2f14c8..28ec6ef9 100644 --- a/filter-map/ex2.js +++ b/filter-map/ex2.js @@ -25,6 +25,11 @@ Sortie attendue: */ function getCampusesTeachingReact(campuses) { + + let best = campuses.filter(lang => lang.curriculums.includes('JS/React') === true) + return best.map(sch => {return sch.city}) + + } module.exports = getCampusesTeachingReact; diff --git a/filter/ex1.js b/filter/ex1.js index 69ced5eb..689bd9a2 100644 --- a/filter/ex1.js +++ b/filter/ex1.js @@ -12,6 +12,7 @@ Sortie attendue: */ function getPositiveNumbers(numbers) { + return numbers.filter(numbers => numbers >= 0) } // Si besoin, tu peux toujours visualiser le résultat avec console.log, diff --git a/filter/ex2.js b/filter/ex2.js index 829b90f4..5086895e 100644 --- a/filter/ex2.js +++ b/filter/ex2.js @@ -16,7 +16,8 @@ Exemple d'entrée: */ function getMultiplesOf(numbers, n) { -} + return numbers.filter(numbers => (numbers % n === 0 ) + )} // Ne pas modifier l'export module.exports = getMultiplesOf; diff --git a/filter/ex3.js b/filter/ex3.js index 6e20e379..67eabd88 100644 --- a/filter/ex3.js +++ b/filter/ex3.js @@ -24,7 +24,9 @@ Sortie attendue: */ function keepStarks(names) { -} + return names.filter(names => names.endsWith('Stark') + + )} // Ne pas modifier l'export module.exports = keepStarks; diff --git a/filter/ex4.js b/filter/ex4.js index cb038bc7..7b6d9062 100644 --- a/filter/ex4.js +++ b/filter/ex4.js @@ -29,6 +29,10 @@ Sortie attendue: */ function filterOnPrice(products, maxPrice) { + + return products.filter(price => price.price <= maxPrice) + + } // Ne pas modifier l'export diff --git a/filter/ex5.js b/filter/ex5.js index e58c104d..8c27ca9e 100644 --- a/filter/ex5.js +++ b/filter/ex5.js @@ -39,6 +39,7 @@ Exemple d'entrée: */ function searchWordFilter(items, search) { + return items.filter(cola => cola.toLowerCase().includes(search.toLowerCase()) === true) } // Ne pas modifier l'export diff --git a/filter/ex6.js b/filter/ex6.js index ed81b883..00f53ede 100644 --- a/filter/ex6.js +++ b/filter/ex6.js @@ -27,6 +27,11 @@ Sortie attendue: */ function filterOffensiveComments(comments, bannedWords) { + for (let i = 0; i comment.toLowerCase().includes(bannedWords[i]) === false) + comments = carotte + } +return comments } // Ne pas modifier l'export diff --git a/map/ex1.js b/map/ex1.js index e337eb79..22b79d8d 100644 --- a/map/ex1.js +++ b/map/ex1.js @@ -22,11 +22,29 @@ En sortie: [ */ function getStringsLength(strings) { + return strings.map(function(aliment){ + return aliment + ' contains ' + aliment.length + ' characters'; + + }); + + } + + + + + + + + + + + // Si besoin, tu peux toujours visualiser le résultat avec console.log, // mais alors, il faut alors lancer l'exercice avec node map/ex1 // console.log(getStringsLength(['Cat', 'Lion', 'Tiger', 'Jaguar', 'Leopard'])); // Ne pas modifier l'export + module.exports = getStringsLength; diff --git a/map/ex2.js b/map/ex2.js index 1b77e1ff..9ae73804 100644 --- a/map/ex2.js +++ b/map/ex2.js @@ -43,6 +43,17 @@ En sortie: [ */ function getFoodCategories(foods) { + return foods.map(aliment => { + if (aliment.isVegetarian === true){ + return (aliment.food + ' is suitable for vegetarians') + + } else { + return (aliment.food + ' is not suitable for vegetarians') + } + + + + }) } diff --git a/map/ex3.js b/map/ex3.js index abfbd879..390fef77 100644 --- a/map/ex3.js +++ b/map/ex3.js @@ -60,6 +60,16 @@ En sortie: */ function getMoviesFreshness(movies) { + return movies.map(movie => { + if (movie.rating < 60){ + movie.label = 'rotten' + } else if (movie.rating >= 60 && movie.rating <= 75){ + movie.label = 'fresh' + } else { + movie.label = 'certified fresh' + } + return movie + }) } diff --git a/map/ex4.js b/map/ex4.js index 2f7f9617..1ff6fba6 100644 --- a/map/ex4.js +++ b/map/ex4.js @@ -52,6 +52,14 @@ Tableau de sortie correspondant (toFixed transforme les nombres en chaînes) */ function getCirclesProperties(radiuses) { + return radiuses.map(obj => { + const tamer = new Object() + tamer.radius = obj; + tamer.circumference = (2 * Math.PI * obj).toFixed(3); + tamer.surface = (Math.PI * obj * obj).toFixed(3); + + return tamer + }) } diff --git a/map/ex5.js b/map/ex5.js index faf7cee5..c2c81554 100644 --- a/map/ex5.js +++ b/map/ex5.js @@ -13,6 +13,21 @@ Tableau renvoyé par multiplyOddIndices: */ function multiplyOddIndices(numbers) { + +return numbers.map( number => { + + if (numbers.indexOf(number) % 2 === 0) { + return number + // nbre pair +} else { + return (numbers.indexOf(number) * number) + // nbre impair } + +}) + +} + + module.exports = multiplyOddIndices; \ No newline at end of file From 2da8a4111ce079012ce340a5ca3d724381b99a23 Mon Sep 17 00:00:00 2001 From: Marot <48023487+cevious77@users.noreply.github.com> Date: Tue, 26 Mar 2019 17:36:10 +0100 Subject: [PATCH 2/2] FINI JEN AI MARRE --- tests/filter-map1.test.js | 2 +- tests/filter-map2.test.js | 2 +- tests/filter-map3.test.js | 2 +- tests/filter-map4.test.js | 2 +- tests/filter1.test.js | 2 +- tests/filter2.test.js | 2 +- tests/filter3.test.js | 2 +- tests/filter4.test.js | 2 +- tests/filter5.test.js | 2 +- tests/filter6.test.js | 2 +- tests/map1.test.js | 2 +- tests/map2.test.js | 2 +- tests/map3.test.js | 2 +- tests/map4.test.js | 2 +- tests/map5.test.js | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/filter-map1.test.js b/tests/filter-map1.test.js index ee17fea4..c655487b 100644 --- a/tests/filter-map1.test.js +++ b/tests/filter-map1.test.js @@ -1,6 +1,6 @@ const getJedisNames = require('../filter-map/ex1.js'); -xdescribe('map + filter - exercice 1', () => { +describe('map + filter - exercice 1', () => { test('getJedisNames', () => { expect(getJedisNames([ diff --git a/tests/filter-map2.test.js b/tests/filter-map2.test.js index 4da7e545..1e3b212b 100644 --- a/tests/filter-map2.test.js +++ b/tests/filter-map2.test.js @@ -1,6 +1,6 @@ const getCampusesTeachingReact = require('../filter-map/ex2.js'); -xdescribe('map + filter - exercice 2', () => { +describe('map + filter - exercice 2', () => { test('getCampusesTeachingReact', () => { expect(getCampusesTeachingReact([ diff --git a/tests/filter-map3.test.js b/tests/filter-map3.test.js index afee9625..02dc631e 100644 --- a/tests/filter-map3.test.js +++ b/tests/filter-map3.test.js @@ -1,6 +1,6 @@ const getStudentsPerCurriculum = require('../filter-map/ex3.js'); -xdescribe('map + filter - exercice 3', () => { +describe('map + filter - exercice 3', () => { test('getStudentsPerCurriculum', () => { expect(getStudentsPerCurriculum( diff --git a/tests/filter-map4.test.js b/tests/filter-map4.test.js index 85c3a546..5822c1dc 100644 --- a/tests/filter-map4.test.js +++ b/tests/filter-map4.test.js @@ -1,6 +1,6 @@ const getActivitiesMembers = require('../filter-map/ex4.js'); -xdescribe('map + filter - exercice 4', () => { +describe('map + filter - exercice 4', () => { test('getActivitiesMembers', () => { expect(getActivitiesMembers( diff --git a/tests/filter1.test.js b/tests/filter1.test.js index 5ae77cb6..2a88e98b 100644 --- a/tests/filter1.test.js +++ b/tests/filter1.test.js @@ -1,6 +1,6 @@ const getPositiveNumbers = require('../filter/ex1.js'); -xdescribe('filter - exercice 1', () => { +describe('filter - exercice 1', () => { test('getPositiveNumbers', () => { expect(getPositiveNumbers([7, -4, 2, 0, -10, 3, 11])) diff --git a/tests/filter2.test.js b/tests/filter2.test.js index 36121852..43d39816 100644 --- a/tests/filter2.test.js +++ b/tests/filter2.test.js @@ -1,6 +1,6 @@ const getMultiplesOf = require('../filter/ex2.js'); -xdescribe('filter - exercice 2', () => { +describe('filter - exercice 2', () => { test('getMultiplesOf', () => { expect(getMultiplesOf([-12, -10, -7, -1, 5, 8, 11, 15, 20, 27], 5)) diff --git a/tests/filter3.test.js b/tests/filter3.test.js index dbb698e9..ff81ff51 100644 --- a/tests/filter3.test.js +++ b/tests/filter3.test.js @@ -1,6 +1,6 @@ const keepStarks = require('../filter/ex3.js'); -xdescribe('filter - exercice 3', () => { +describe('filter - exercice 3', () => { test('keepStarks', () => { expect(keepStarks([ diff --git a/tests/filter4.test.js b/tests/filter4.test.js index 76beb025..0fe67cb8 100644 --- a/tests/filter4.test.js +++ b/tests/filter4.test.js @@ -23,7 +23,7 @@ const products = [ } ]; -xdescribe('filter - exercice 4', () => { +describe('filter - exercice 4', () => { test('filterOnPrice (price <= 500)', () => { expect(filterOnPrice(products, 500)) diff --git a/tests/filter5.test.js b/tests/filter5.test.js index 805d9be8..c0bbf48e 100644 --- a/tests/filter5.test.js +++ b/tests/filter5.test.js @@ -1,6 +1,6 @@ const searchWordFilter = require('../filter/ex5.js'); -xdescribe('filter - exercice 5', () => { +describe('filter - exercice 5', () => { test('searchWordFilter', () => { expect(searchWordFilter([ diff --git a/tests/filter6.test.js b/tests/filter6.test.js index 7428ee7a..6a5befe4 100644 --- a/tests/filter6.test.js +++ b/tests/filter6.test.js @@ -1,6 +1,6 @@ const filterOffensiveComments = require('../filter/ex6.js'); -xdescribe('filter - exercice 6', () => { +describe('filter - exercice 6', () => { test('filterOffensiveComments', () => { expect(filterOffensiveComments([ diff --git a/tests/map1.test.js b/tests/map1.test.js index b2a436be..38f8ea1e 100644 --- a/tests/map1.test.js +++ b/tests/map1.test.js @@ -1,6 +1,6 @@ const getStringsLength = require('../map/ex1.js'); -xdescribe('map - exercice 1', () => { +describe('map - exercice 1', () => { test('getStringsLength', () => { expect(getStringsLength([ diff --git a/tests/map2.test.js b/tests/map2.test.js index 09a20471..f2701437 100644 --- a/tests/map2.test.js +++ b/tests/map2.test.js @@ -1,6 +1,6 @@ const getFoodCategories = require('../map/ex2.js'); -xdescribe('map - exercice 2', () => { +describe('map - exercice 2', () => { test('getFoodCategories', () => { expect(getFoodCategories( [ diff --git a/tests/map3.test.js b/tests/map3.test.js index 00272563..1dd01c1a 100644 --- a/tests/map3.test.js +++ b/tests/map3.test.js @@ -1,6 +1,6 @@ const getMoviesFreshness = require('../map/ex3.js'); -xdescribe('map - exercice 3', () => { +describe('map - exercice 3', () => { test('getMoviesFreshness', () => { expect(getMoviesFreshness( diff --git a/tests/map4.test.js b/tests/map4.test.js index c01a322e..d16ec82c 100644 --- a/tests/map4.test.js +++ b/tests/map4.test.js @@ -1,6 +1,6 @@ const getCirclesProperties = require('../map/ex4.js'); -xdescribe('map - exercice 4', () => { +describe('map - exercice 4', () => { test('getCirclesProperties', () => { expect(getCirclesProperties( [ diff --git a/tests/map5.test.js b/tests/map5.test.js index 67b1a351..461a28ab 100644 --- a/tests/map5.test.js +++ b/tests/map5.test.js @@ -1,6 +1,6 @@ const multiplyOddIndices = require('../map/ex5.js'); -xdescribe('map - exercice 5', () => { +describe('map - exercice 5', () => { test('multiplyOddIndices', () => { expect(multiplyOddIndices([3, 8, 11, 13, 19, 7]))