From 08084277e51c370b953d83584e8e31484de7575f Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 00:06:41 -0400 Subject: [PATCH 01/13] Solve kitty prompts --- package-lock.json | 1 + prototypes/index.js | 31 +++++++++++++++++++++++-------- test/prototype-test.js | 14 +++++++------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index f4bd97e1..76357926 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "jsFun", "version": "1.0.0", "license": "ISC", "devDependencies": { diff --git a/prototypes/index.js b/prototypes/index.js index b6f750c3..21c925ea 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -20,26 +20,28 @@ const { dinosaurs, humans, movies } = require('./datasets/dinosaurs'); // DATASET: kitties from ./datasets/kitties const kittyPrompts = { - orangePetNames() { + orangePetNames(animals) { // Return an array of just the names of kitties who are orange e.g. // ['Tiger', 'Snickers'] /* CODE GOES HERE */ - + return animals + .filter(animal => animal.color === "orange") + .map(animal => animal.name); // Annotation: // Write your annotation here as a comment }, - sortByAge() { + sortByAge(animals) { // Sort the kitties by their age /* CODE GOES HERE */ - + return animals.sort((a, b) => b.age - a.age); // Annotation: // Write your annotation here as a comment }, - growUp() { + growUp(animals) { // Return an array of kitties who have all grown up by 2 years e.g. // [{ // name: 'Felicia', @@ -54,8 +56,12 @@ const kittyPrompts = { // ...etc] /* CODE GOES HERE */ + return animals.map(animal => { + animal.age += 2; + return animal; + }); } -}; +} // PLEASE READ----------------------- // Currently, your functions are probably using the `kitties` global import variable. @@ -77,7 +83,7 @@ const kittyPrompts = { // DATASET: clubs from ./datasets/clubs const clubPrompts = { - membersBelongingToClubs() { + membersBelongingToClubs(clubList) { // Your function should access the clubs data through a parameter (it is being passed as an argument in the test file) // Create an object whose keys are the names of people, and whose values are // arrays that include the names of the clubs that person is a part of. e.g. @@ -88,7 +94,16 @@ const clubPrompts = { // } /* CODE GOES HERE */ - + return clubList.reduce((compilation, clubItem) => { + clubItem.members.forEach(member => { + if (!compilation[member]) { + compilation[member] = []; + } + compilation[member].push(clubItem.club) + return compilation; + }) + return compilation; + }, {}) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index 6366ee76..2154d9ac 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -25,13 +25,13 @@ const { describe("PROTOTYPES", () => { describe("Kitty Prompts", () => { - it.skip("orangeKittyNames", () => { + it("orangeKittyNames", () => { const e = kittyPrompts.orangePetNames(kitties); expect(e).to.deep.equal(["Tiger", "Snickers"]) }); - it.skip("sortByAge", () => { + it("sortByAge", () => { const e = kittyPrompts.sortByAge(kitties); expect(e).to.deep.equal([{ @@ -53,7 +53,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("growUp", () => { + it("growUp", () => { const e = kittyPrompts.growUp(kitties); expect(e).to.deep.equal([{ @@ -75,13 +75,13 @@ describe("PROTOTYPES", () => { }]) }) describe('kittyPrompts refactor', () => { - it.skip('should be able to handle orange puppers', () => { + it('should be able to handle orange puppers', () => { const e = kittyPrompts.orangePetNames(puppers); expect(e).to.deep.equal(["Hatchet", "Butter"]) }) - it.skip('should sort pups too', () => { + it('should sort pups too', () => { const e = kittyPrompts.sortByAge(puppers); expect(e).to.deep.equal([{ @@ -103,7 +103,7 @@ describe("PROTOTYPES", () => { }]) }) - it.skip('should age puppers too', () => { + it('should age puppers too', () => { const e = kittyPrompts.growUp(puppers); expect(e).to.deep.equal([{ @@ -128,7 +128,7 @@ describe("PROTOTYPES", () => { }); describe("Club Prompts", () => { - it.skip("membersBelongingToClubs", () => { + it("membersBelongingToClubs", () => { const e = clubPrompts.membersBelongingToClubs(clubs); expect(e).to.deep.equal({ From 4393f87abfd6dc36d5c1889901b6a2c1279c4f0e Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 00:52:44 -0400 Subject: [PATCH 02/13] Solve mod prompt --- prototypes/index.js | 7 ++++++- test/prototype-test.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 21c925ea..73fd6c5a 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -100,7 +100,6 @@ const clubPrompts = { compilation[member] = []; } compilation[member].push(clubItem.club) - return compilation; }) return compilation; }, {}) @@ -138,6 +137,12 @@ const modPrompts = { // ] /* CODE GOES HERE */ + return mods.map(modItem => { + return { + mod: modItem.mod, + studentsPerInstructor: modItem.students/modItem.instructors + } + }) // Annotation: // Write your annotation here as a comment diff --git a/test/prototype-test.js b/test/prototype-test.js index 2154d9ac..a7479f66 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -147,7 +147,7 @@ describe("PROTOTYPES", () => { }); describe("Mod Prompts", () => { - it.skip("studentsPerMod", () => { + it("studentsPerMod", () => { const e = modPrompts.studentsPerMod(); expect(e).to.deep.equal([{ From 5d18a8e16513b1b6510f2adb8292e248a1bf7389 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 01:38:39 -0400 Subject: [PATCH 03/13] Solve cake prompts --- prototypes/index.js | 26 +++++++++++++++++++++----- test/prototype-test.js | 10 +++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 73fd6c5a..d4120fd5 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -177,7 +177,7 @@ const cakePrompts = { // ] /* CODE GOES HERE */ - + return cakes.map(cake => ({flavor: cake.cakeFlavor, inStock: cake.inStock})); // Annotation: // Write your annotation here as a comment }, @@ -204,7 +204,7 @@ const cakePrompts = { // ] /* CODE GOES HERE */ - + return cakes.filter(cake => cake.inStock); // Annotation: // Write your annotation here as a comment }, @@ -214,7 +214,7 @@ const cakePrompts = { // 59 /* CODE GOES HERE */ - + return cakes.reduce((total, cake) => cake.inStock + total, 0) // Annotation: // Write your annotation here as a comment }, @@ -225,7 +225,14 @@ const cakePrompts = { // ['dutch process cocoa', 'toasted sugar', 'smoked sea salt', 'berries', ..etc] /* CODE GOES HERE */ - + return cakes.reduce((toppings, cake) => { + cake.toppings.forEach(topping => { + if (!toppings.includes(topping)) { + toppings.push(topping); + } + }) + return toppings; + }, []) // Annotation: // Write your annotation here as a comment }, @@ -242,7 +249,16 @@ const cakePrompts = { // } /* CODE GOES HERE */ - + return cakes.reduce((list, cake) => { + cake.toppings.forEach(topping => { + if (!list[topping]) { + list[topping] = 1; + } else { + list[topping]++; + } + }) + return list; + }, {}) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index a7479f66..b4384216 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -167,7 +167,7 @@ describe("PROTOTYPES", () => { }); describe("Cake Prompts", () => { - it.skip("stockPerCake", () => { + it("stockPerCake", () => { const e = cakePrompts.stockPerCake(); expect(e).to.deep.equal([{ @@ -191,7 +191,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("onlyInStock", () => { + it("onlyInStock", () => { const e = cakePrompts.onlyInStock(); expect(e).to.deep.equal([{ @@ -221,19 +221,19 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("totalInventory", () => { + it("totalInventory", () => { const e = cakePrompts.totalInventory(); expect(e).to.deep.equal(59) }); - it.skip("allToppings", () => { + it("allToppings", () => { const e = cakePrompts.allToppings(); expect(e).to.deep.equal(["dutch process cocoa", "toasted sugar", "smoked sea salt", "berries", "edible flowers", "mint", "cranberry", "crystallized ginger"]) }); - it.skip("groceryList", () => { + it("groceryList", () => { const e = cakePrompts.groceryList(); expect(e).to.deep.equal({ From a3bc14dce99537ead6dba9e25568ff16686c9422 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 01:59:17 -0400 Subject: [PATCH 04/13] Solve classroom prompts --- prototypes/index.js | 13 ++++++++++--- test/prototype-test.js | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index d4120fd5..6186593c 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -292,7 +292,7 @@ const classPrompts = { // ] /* CODE GOES HERE */ - + return classrooms.filter(classroom => classroom.program === "FE"); // Annotation: // Write your annotation here as a comment }, @@ -306,7 +306,14 @@ const classPrompts = { // } /* CODE GOES HERE */ - + return classrooms.reduce((totalCapacity, classroom) => { + if(classroom.program === "FE") { + totalCapacity.feCapacity += classroom.capacity; + } else { + totalCapacity.beCapacity += classroom.capacity; + } + return totalCapacity; + }, {feCapacity:0, beCapacity: 0}) // Annotation: // Write your annotation here as a comment }, @@ -315,7 +322,7 @@ const classPrompts = { // Return the array of classrooms sorted by their capacity (least capacity to greatest) /* CODE GOES HERE */ - + return classrooms.sort((a,b) => a.capacity - b.capacity); // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index b4384216..f339b46a 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -250,7 +250,7 @@ describe("PROTOTYPES", () => { }); describe("Class Prompts", () => { - it.skip("feClassrooms", () => { + it("feClassrooms", () => { const e = classPrompts.feClassrooms(); expect(e).to.deep.equal([{ @@ -272,7 +272,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("totalCapacities", () => { + it("totalCapacities", () => { const e = classPrompts.totalCapacities(); expect(e).to.deep.equal({ @@ -281,7 +281,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("sortByCapacity", () => { + it("sortByCapacity", () => { const e = classPrompts.sortByCapacity(); expect(e).to.deep.equal([{ From bc009ba7cebbc7749352fd1ccfe3c950dd3f0aae Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 02:36:13 -0400 Subject: [PATCH 05/13] Solve book prompts --- prototypes/index.js | 15 +++++++++++---- test/prototype-test.js | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 6186593c..83ebbc88 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -337,7 +337,7 @@ const classPrompts = { // DATASET: books from './datasets/books const bookPrompts = { - removeViolence() { + removeViolence(bookCollection) { // Your function should access the books data through a parameter (it is being passed as an argument in the test file) // return an array of all book titles that are not horror or true crime. Eg: @@ -349,12 +349,14 @@ const bookPrompts = { /* CODE GOES HERE */ - + return bookCollection + .filter(book => book.genre !== "Horror" && book.genre !== "True Crime") + .map(book => book.title) // Annotation: // Write your annotation here as a comment }, - getNewBooks() { + getNewBooks(bookCollection) { // return an array of objects containing all books that were // published in the 90's and 00's. Inlucde the title and the year Eg: @@ -363,7 +365,9 @@ const bookPrompts = { // { title: 'The Curious Incident of the Dog in the Night-Time', year: 2003 }] /* CODE GOES HERE */ - + return bookCollection + .filter(book => book.published >= 1990) + .map(book => ({title: book.title, year: book.published})) // Annotation: // Write your annotation here as a comment }, @@ -379,6 +383,9 @@ const bookPrompts = { // { title: 'The Curious Incident of the Dog in the Night-Time', year: 2003 }] /* CODE GOES HERE */ + return books + .filter(book => book.published > year) + .map(book => ({title: book.title, year: book.published})); // Annotation: // Write your annotation here as a comment diff --git a/test/prototype-test.js b/test/prototype-test.js index f339b46a..fd723ab7 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -321,7 +321,7 @@ describe("PROTOTYPES", () => { }); describe("Book prompts", () => { - it.skip("removeViolence", () => { + it("removeViolence", () => { const e = bookPrompts.removeViolence(books); expect(e).to.deep.equal(['1984', @@ -340,7 +340,7 @@ describe("PROTOTYPES", () => { 'Treasure Island']) }); - it.skip("getNewBooks", () => { + it("getNewBooks", () => { const e = bookPrompts.getNewBooks(books); expect(e).to.deep.equal([{ @@ -352,7 +352,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("getBooksByYear", () => { + it("getBooksByYear", () => { const e = bookPrompts.getBooksByYear(books, 1990); expect(e).to.deep.equal([{ From a74b8957dfc088f8c59b8e1800e5149dac076e7f Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 21:32:34 -0400 Subject: [PATCH 06/13] Solve weather prompts --- prototypes/index.js | 13 ++++++++++--- test/prototype-test.js | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 83ebbc88..5fbfb7a3 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -408,7 +408,7 @@ const weatherPrompts = { // [ 40, 40, 44.5, 43.5, 57, 35, 65.5, 62, 14, 46.5 ] /* CODE GOES HERE */ - + return weather.map(area => (area.temperature.high + area.temperature.low)/2); // Annotation: // Write your annotation here as a comment }, @@ -421,7 +421,9 @@ const weatherPrompts = { // 'Raleigh, North Carolina is mostly sunny.' ] /* CODE GOES HERE */ - + return weather + .filter(area => area.type.includes("sunny")) + .map(area => `${area.location} is ${area.type}.`); // Annotation: // Write your annotation here as a comment }, @@ -436,7 +438,12 @@ const weatherPrompts = { // } /* CODE GOES HERE */ - + return weather.reduce((mostHumidArea, area) => { + if (area.humidity > mostHumidArea.humidity) { + mostHumidArea = area; + } + return mostHumidArea; + }, {humidity: 0}) // Annotation: // Write your annotation here as a comment diff --git a/test/prototype-test.js b/test/prototype-test.js index fd723ab7..791dddf1 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -376,20 +376,20 @@ describe("PROTOTYPES", () => { }); describe("Weather prompts", () => { - it.skip("getAverageTemps", () => { + it("get`AverageTemps", () => { const e = weatherPrompts.getAverageTemps(); expect(e).to.deep.equal([ 40, 40, 44.5, 43.5, 57, 35, 65.5, 62, 14, 46.5 ]) }), - it.skip("findSunnySpots", () => { + it("findSunnySpots", () => { const e = weatherPrompts.findSunnySpots(); expect(e).to.deep.equal(['Atlanta, Georgia is sunny.', 'New Orleans, Louisiana is sunny.', 'Raleigh, North Carolina is mostly sunny.'] ) }), - it.skip("findHighestHumidity", () => { + it("findHighestHumidity", () => { const e = weatherPrompts.findHighestHumidity(); expect(e).to.deep.equal({ From 976d35751d62a8914b0cd33facdae30c5269c818 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 22:09:43 -0400 Subject: [PATCH 07/13] Solve national parks prompts --- prototypes/index.js | 20 +++++++++++++++++--- test/prototype-test.js | 6 +++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 5fbfb7a3..c601eb7e 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -469,7 +469,14 @@ const nationalParksPrompts = { //} /* CODE GOES HERE */ - + return nationalParks.reduce((updatedList, park) => { + if (park.visited) { + updatedList.parksVisited.push(park.name); + } else { + updatedList.parksToVisit.push(park.name); + } + return updatedList; + }, {parksToVisit: [], parksVisited: []}) // Annotation: // Write your annotation here as a comment }, @@ -485,7 +492,7 @@ const nationalParksPrompts = { /* CODE GOES HERE */ - + return nationalParks.map(park => ({[park.location]: park.name})) // Annotation: // Write your annotation here as a comment }, @@ -507,7 +514,14 @@ const nationalParksPrompts = { // 'rock climbing' ] /* CODE GOES HERE */ - + return nationalParks.reduce((allActivities, park) => { + park.activities.forEach(activity => { + if (!allActivities.includes(activity)) { + allActivities.push(activity); + } + }) + return allActivities; + }, []) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index 791dddf1..1b38b3d8 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -402,7 +402,7 @@ describe("PROTOTYPES", () => { }); describe("National Park Prompts", () => { - it.skip("getParkVisitList", () => { + it("getParkVisitList", () => { const e = nationalParksPrompts.getParkVisitList(); expect(e).to.deep.equal({ @@ -410,7 +410,7 @@ describe("PROTOTYPES", () => { parksVisited: ['Rocky Mountain', 'Acadia', 'Zion'] }) }), - it.skip("getParkActivities", () => { + it("getParkActivities", () => { const e = nationalParksPrompts.getParkActivities(); expect(e).to.deep.equal( @@ -428,7 +428,7 @@ describe("PROTOTYPES", () => { 'rock climbing' ]) }), - it.skip("getParkInEachState", () => { + it("getParkInEachState", () => { const e = nationalParksPrompts.getParkInEachState(); expect(e).to.deep.equal( From 8e5ead4846c36f13274bd164f575a14b926e1935 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Fri, 5 May 2023 22:55:37 -0400 Subject: [PATCH 08/13] Solve brewery prompts --- prototypes/index.js | 19 +++++++++++++++---- test/prototype-test.js | 8 ++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index c601eb7e..ba4abff1 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -547,7 +547,7 @@ const breweryPrompts = { // 40 /* CODE GOES HERE */ - + return breweries.reduce((beerCount, brewery) => beerCount + brewery.beers.length, 0); // Annotation: // Write your annotation here as a comment }, @@ -562,7 +562,7 @@ const breweryPrompts = { // ] /* CODE GOES HERE */ - + return breweries.map(brewery => ({name: brewery.name, beerCount: brewery.beers.length})); // Annotation: // Write your annotation here as a comment }, @@ -574,7 +574,8 @@ const breweryPrompts = { /* CODE GOES HERE */ - + return breweries.find(brewery => brewery.name === breweryName).beers.length + // .map(brewery => brewery.beers.length); // Annotation: // Write your annotation here as a comment }, @@ -583,8 +584,18 @@ const breweryPrompts = { // Return the beer which has the highest ABV of all beers // e.g. // { name: 'Barrel Aged Nature\'s Sweater', type: 'Barley Wine', abv: 10.9, ibu: 40 } - + /* CODE GOES HERE */ + function topAbvBeer(beers) { + return beers.reduce((topAbv, beer) => { + if (topAbv.abv < beer.abv) { + topAbv = beer; + } + return topAbv; + },{abv: 0}) + } + return topAbvBeer(breweries.map(brewery => topAbvBeer(brewery.beers))); + // Annotation: // Write your annotation here as a comment diff --git a/test/prototype-test.js b/test/prototype-test.js index 1b38b3d8..d15ad959 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -444,13 +444,13 @@ describe("PROTOTYPES", () => { }); describe("Brewery Prompts", () => { - it.skip("getBeerCount", () => { + it("getBeerCount", () => { const e = breweryPrompts.getBeerCount(); expect(e).to.deep.equal(40) }); - it.skip("getBreweryBeerCount", () => { + it("getBreweryBeerCount", () => { const e = breweryPrompts.getBreweryBeerCount(); expect(e).to.deep.equal([{ @@ -471,7 +471,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("getSingleBreweryBeerCount", () => { + it("getSingleBreweryBeerCount", () => { const ratioCount = breweryPrompts.getSingleBreweryBeerCount('Ratio Beerworks'); const plattCount = breweryPrompts.getSingleBreweryBeerCount('Platt Park Brewing Co.'); @@ -479,7 +479,7 @@ describe("PROTOTYPES", () => { expect(plattCount).to.equal(7); }); - it.skip("findHighestAbvBeer", () => { + it("findHighestAbvBeer", () => { const e = breweryPrompts.findHighestAbvBeer(); expect(e).to.deep.equal({ From fa2333738c255fb5dd2705d9b2d49f79b87af84e Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Sat, 6 May 2023 04:11:28 -0400 Subject: [PATCH 09/13] Solve all solo data sets and turingPrompts --- prototypes/index.js | 67 ++++++++++++++++++++++++++++++++++++++---- test/prototype-test.js | 18 ++++++------ 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index ba4abff1..32e8194f 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -618,7 +618,7 @@ const boardGamePrompts = { // ["Chess", "Catan", "Checkers", "Pandemic", "Battle Ship", "Azul", "Ticket to Ride"] /* CODE GOES HERE */ - + return boardGames[type].map(game => game.name); // Annotation: // Write your annotation here as a comment }, @@ -630,7 +630,9 @@ const boardGamePrompts = { // ["Candy Land", "Connect Four", "Operation", "Trouble"] /* CODE GOES HERE */ - + return (boardGames[type] + .map(game => game.name) + .sort()) // Annotation: // Write your annotation here as a comment }, @@ -641,7 +643,13 @@ const boardGamePrompts = { // { name: 'Codenames', rating: 7.4, maxPlayers: 8 }, /* CODE GOES HERE */ - + return boardGames[type] + .reduce((highestRated, game) => { + if (game.rating > highestRated.rating) { + highestRated = game; + } + return highestRated; + }, {rating: 0}) // Annotation: // Write your annotation here as a comment }, @@ -652,7 +660,9 @@ const boardGamePrompts = { // note: do not worry about rounding your result. /* CODE GOES HERE */ - + let totalScore = boardGames[type] + .reduce(((total, game) => total + game.rating), 0); + return totalScore/boardGames[type].length; // Annotation: // Write your annotation here as a comment }, @@ -664,7 +674,11 @@ const boardGamePrompts = { // note: do not worry about rounding your result. /* CODE GOES HERE */ + let filteredGames = boardGames[type] + .filter(game => game.maxPlayers === maximumPlayers); + return filteredGames + .reduce((total, game) => total + game.rating, 0)/filteredGames.length; // Annotation: // Write your annotation here as a comment } @@ -711,7 +725,13 @@ const turingPrompts = { // ] /* CODE GOES HERE */ - + return instructors.map(instructor => { + let students = cohorts.find(cohort => cohort.module === instructor.module).studentCount; + return { + name: instructor.name, + studentCount: students + } + }) // Annotation: // Write your annotation here as a comment }, @@ -724,7 +744,12 @@ const turingPrompts = { // } /* CODE GOES HERE */ - + return cohorts.reduce((cohortList, singleCohort) => { + let cohortKey = `cohort${singleCohort.cohort}`; + let teacherCount = instructors.filter(instructor => instructor.module === singleCohort.module).length; + cohortList[cohortKey] = singleCohort.studentCount/teacherCount; + return cohortList; + }, {}) // Annotation: // Write your annotation here as a comment }, @@ -745,7 +770,20 @@ const turingPrompts = { // } /* CODE GOES HERE */ + let canTeach = (instructor, cohort) => { + return cohort.curriculum.some(subject => instructor.teaches.includes(subject)); + } + return instructors.reduce((instructorsList, teacher) => { + let teachableModules = []; + cohorts.forEach(cohort => { + if (canTeach(teacher, cohort)) { + teachableModules.push(cohort.module); + } + }); + instructorsList[teacher.name] = teachableModules; + return instructorsList; + }, {}) // Annotation: // Write your annotation here as a comment }, @@ -761,7 +799,24 @@ const turingPrompts = { // } /* CODE GOES HERE */ + let checkForTeacher = (subject) => { + let availableTeachers = []; + instructors.forEach(instructor => { + if (instructor.teaches.includes(subject)) { + availableTeachers.push(instructor.name); + } + }) + return availableTeachers; + } + return cohorts.reduce((allSubjects, cohort) => { + cohort.curriculum.forEach(subject => { + if (!allSubjects[subject]) { + allSubjects[subject] = checkForTeacher(subject); + } + }); + return allSubjects; + }, {}) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index d15ad959..22a02d9c 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -492,7 +492,7 @@ describe("PROTOTYPES", () => { }); describe("Board Game Prompts", () => { - it.skip("listGames", () => { + it("listGames", () => { const strategyGames = boardGamePrompts.listGames('strategy'); const childrensGames = boardGamePrompts.listGames('childrens'); const partyGames = boardGamePrompts.listGames('party'); @@ -502,7 +502,7 @@ describe("PROTOTYPES", () => { expect(partyGames).to.deep.equal(["Werewolf", "Cards Against Humanity", "Codenames", "Sushi Go! Party", "Tsuro"]); }); - it.skip("listGamesAlphabetically", () => { + it("listGamesAlphabetically", () => { const strategyGames = boardGamePrompts.listGamesAlphabetically('strategy'); const childrensGames = boardGamePrompts.listGamesAlphabetically('childrens'); const partyGames = boardGamePrompts.listGamesAlphabetically('party'); @@ -512,7 +512,7 @@ describe("PROTOTYPES", () => { expect(partyGames).to.deep.equal(["Cards Against Humanity", "Codenames", "Sushi Go! Party", "Tsuro", "Werewolf"]); }); - it.skip("findHighestRatedGamesByType", () => { + it("findHighestRatedGamesByType", () => { const highestStrategy = boardGamePrompts.findHighestRatedGamesByType('strategy'); const highestChildrens = boardGamePrompts.findHighestRatedGamesByType('childrens'); const highestParty = boardGamePrompts.findHighestRatedGamesByType('party'); @@ -522,7 +522,7 @@ describe("PROTOTYPES", () => { expect(highestParty).to.deep.equal({ name: 'Codenames', rating: 7.4, maxPlayers: 8 }); }); - it.skip("averageScoreByType", () => { + it("averageScoreByType", () => { const avScoreStrat = boardGamePrompts.averageScoreByType('strategy'); const avScoreChildren = boardGamePrompts.averageScoreByType('childrens'); const avScoreParty = boardGamePrompts.averageScoreByType('party'); @@ -532,7 +532,7 @@ describe("PROTOTYPES", () => { expect(Math.round(avScoreParty * 100) / 100).to.equal(6.54); }); - it.skip("averageScoreByTypeAndPlayers", () => { + it ("averageScoreByTypeAndPlayers", () => { const avScoreStrat = boardGamePrompts.averageScoreByTypeAndPlayers('strategy', 2); const avScoreChildren = boardGamePrompts.averageScoreByTypeAndPlayers('childrens', 4); const avScoreParty = boardGamePrompts.averageScoreByTypeAndPlayers('party', 8); @@ -544,7 +544,7 @@ describe("PROTOTYPES", () => { }) describe("Turing Prompts", () => { - it.skip("studentsForEachInstructor", () => { + it("studentsForEachInstructor", () => { const e = turingPrompts.studentsForEachInstructor(); expect(e).to.deep.equal([{ @@ -577,7 +577,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("studentsPerInstructor", () => { + it("studentsPerInstructor", () => { const e = turingPrompts.studentsPerInstructor(); expect(e).to.deep.equal({ @@ -588,7 +588,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("modulesPerTeacher", () => { + it("modulesPerTeacher", () => { const e = turingPrompts.modulesPerTeacher(); expect(e).to.deep.equal({ @@ -604,7 +604,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("curriculumPerTeacher", () => { + it("curriculumPerTeacher", () => { const e = turingPrompts.curriculumPerTeacher(); expect(e).to.deep.equal({ From 8fae4cfff9df7024caacc34ce8fe9889c7101757 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Sat, 6 May 2023 20:28:03 -0400 Subject: [PATCH 10/13] Solve bosses prompts --- prototypes/index.js | 8 +++++++- test/prototype-test.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 32e8194f..3efd8454 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -850,7 +850,13 @@ const bossPrompts = { // ] /* CODE GOES HERE */ - + let allBosses = Object.keys(bosses); + return allBosses.map(boss => { + return { + bossName: bosses[boss].name, + sidekickLoyalty: bosses[boss].sidekicks.reduce((loyalty, sidekick) => loyalty + sidekicks.find(theSidekick => theSidekick.name === sidekick.name).loyaltyToBoss, 0) + } + }) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index 22a02d9c..1ea252e1 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -624,7 +624,7 @@ describe("PROTOTYPES", () => { }); describe("Boss Prompts", () => { - it.skip("bossLoyalty", () => { + it("bossLoyalty", () => { const e = bossPrompts.bossLoyalty(); expect(e).to.deep.equal([{ From 86cfc4e42668c34d559306d0d70d202133ca5d13 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Sat, 6 May 2023 22:21:17 -0400 Subject: [PATCH 11/13] Solve astronomy prompts --- prototypes/index.js | 24 ++++++++++++++++++++++-- test/prototype-test.js | 6 +++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 3efd8454..73d8bae9 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -911,7 +911,18 @@ const astronomyPrompts = { // ] /* CODE GOES HERE */ + let constellationKeys = Object.keys(constellations); + let allConstellationNames = constellationKeys.reduce((nameList, constellation) => { + nameList.push(...constellations[constellation].alternateNames) + return nameList; + }, []); + let constellationStars = []; + + allConstellationNames.forEach(aConstellation => { + constellationStars.push(...stars.filter(star => star.constellation === aConstellation)) + }) + return constellationStars; // Annotation: // Write your annotation here as a comment }, @@ -928,7 +939,13 @@ const astronomyPrompts = { // } /* CODE GOES HERE */ - + return stars.reduce((starList, star) => { + if (!starList[star.color]) { + starList[star.color] = []; + } + starList[star.color].push(star); + return starList; + }, {}) // Annotation: // Write your annotation here as a comment }, @@ -950,7 +967,10 @@ const astronomyPrompts = { /* CODE GOES HERE */ - + return stars + .sort((a,b) => a.visualMagnitude - b.visualMagnitude) + .map(star => star.constellation) + .filter(constellation => constellation.length) // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index 1ea252e1..cdf783d2 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -641,7 +641,7 @@ describe("PROTOTYPES", () => { }); describe("Astronomy Prompts", () => { - it.skip("starsInConstellations", () => { + it("starsInConstellations", () => { const e = astronomyPrompts.starsInConstellations(); expect(e).to.deep.equal([{ @@ -674,7 +674,7 @@ describe("PROTOTYPES", () => { ]) }); - it.skip("starsByColor", () => { + it("starsByColor", () => { const e = astronomyPrompts.starsByColor(); expect(e).to.deep.equal({ @@ -752,7 +752,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("constellationsStarsExistIn", () => { + it("constellationsStarsExistIn", () => { const e = astronomyPrompts.constellationsStarsExistIn(); expect(e).to.deep.equal(["Canis Major", "Carina", "Boötes", "Auriga", "Orion", "Lyra", "Canis Minor", "The Plow", "Orion", "The Little Dipper"]) From da1ddbad7b738da4c1636890f4de8dbd9a28af4d Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Sat, 6 May 2023 23:01:40 -0400 Subject: [PATCH 12/13] Solve ultima prompts --- prototypes/index.js | 17 +++++++++++++++-- test/prototype-test.js | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index 73d8bae9..ac7ed124 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -1000,7 +1000,11 @@ const ultimaPrompts = { // Answer => 113 /* CODE GOES HERE */ - + let allWeapons = characters.reduce((list, character) => { + list.push(...character.weapons); + return list; + }, []); + return allWeapons.reduce((totalDamage, weapon) => totalDamage + weapons[weapon].damage , 0) // Annotation: // Write your annotation here as a comment }, @@ -1011,7 +1015,16 @@ const ultimaPrompts = { // ex: [ { Avatar: { damage: 27, range: 24 }, { Iolo: {...}, ...} /* CODE GOES HERE */ - + return characters.map(character => { + let characterStat = character.weapons.reduce((stats, weapon) => { + stats.damage += weapons[weapon].damage; + stats.range += weapons[weapon].range; + return stats; + }, {damage: 0, range:0}) + return { + [character.name]: characterStat + } + }) // Annotation: // Write your annotation here as a comment }, diff --git a/test/prototype-test.js b/test/prototype-test.js index cdf783d2..481ab58d 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -760,13 +760,13 @@ describe("PROTOTYPES", () => { }); describe("Ultima Prompts", () => { - it.skip("totalDamage", () => { + it("totalDamage", () => { const e = ultimaPrompts.totalDamage(); expect(e).to.deep.equal(113) }); - it.skip("charactersByTotal", () => { + it("charactersByTotal", () => { const e = ultimaPrompts.charactersByTotal(); expect(e).to.deep.equal([{ From ca3e17b29f15eb6866be85f7fd17c5d4b0541853 Mon Sep 17 00:00:00 2001 From: Taranveer Singh Date: Sun, 7 May 2023 02:27:22 -0400 Subject: [PATCH 13/13] Solve dinosaurs prompts --- prototypes/index.js | 76 +++++++++++++++++++++++++++++++++++++++++- test/prototype-test.js | 8 ++--- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/prototypes/index.js b/prototypes/index.js index ac7ed124..4cfe462c 100644 --- a/prototypes/index.js +++ b/prototypes/index.js @@ -1060,7 +1060,16 @@ const dinosaurPrompts = { // } /* CODE GOES HERE */ - + return movies.reduce((dinoCounts, movie) => { + let awesomeCount = movie.dinos.reduce((count, dino) => { + if (dinosaurs[dino].isAwesome) { + count++; + }; + return count; + }, 0); + dinoCounts[movie.title] = awesomeCount; + return dinoCounts; + }, {}) // Annotation: // Write your annotation here as a comment }, @@ -1092,7 +1101,22 @@ const dinosaurPrompts = { */ /* CODE GOES HERE */ + let getAvgAge = movie => { + const refYear = movie.yearReleased; + let totalAge = movie.cast.reduce((total, actor) => { + return total + refYear - humans[actor].yearBorn; + }, 0) + let numberActors = movie.cast.length; + return Math.floor(totalAge/numberActors); + } + return movies.reduce((accumulator, movie) => { + if (!accumulator[movie.director]) { + accumulator[movie.director] = {} + } + accumulator[movie.director][movie.title] = getAvgAge(movie); + return accumulator; + }, {}) // Annotation: // Write your annotation here as a comment }, @@ -1124,6 +1148,36 @@ const dinosaurPrompts = { */ /* CODE GOES HERE */ + let castCharacters = movies.reduce((fullCast, movie) => { + fullCast.push(movie.cast); + return fullCast.flat(); + }, []); + + let humanNames = Object.keys(humans); + let uncastNames = []; + humanNames.forEach(humanName => { + if (!castCharacters.includes(humanName)) { + uncastNames.push(humanName); + } + }) + + return uncastNames + .map(actorName => { + let actor = { + name: actorName, + nationality: humans[actorName].nationality, + imdbStarMeterRating: humans[actorName].imdbStarMeterRating + }; + return actor; + }) + .sort((a,b) => { + if (a.nationality > b.nationality) { + return 1; + } else { + return -1; + } + }); + // Annotation: // Write your annotation here as a comment @@ -1146,7 +1200,27 @@ const dinosaurPrompts = { */ /* CODE GOES HERE */ + let getMovieReleaseAges = actorName => { + let releaseYears = []; + movies.forEach(movie => { + if (movie.cast.includes(actorName)) { + releaseYears.push(movie.yearReleased); + } + }) + let releaseAges = releaseYears.map(year => year - humans[actorName].yearBorn); + return releaseAges; + } + + let allHumans = Object.keys(humans); + let actorsWithAge = allHumans.map(human => { + return { + name: human, + ages: getMovieReleaseAges(human) + }; + }) + let castedActorAges = actorsWithAge.filter(actor => actor.ages.length); + return castedActorAges; // Annotation: // Write your annotation here as a comment } diff --git a/test/prototype-test.js b/test/prototype-test.js index 481ab58d..29a000e3 100644 --- a/test/prototype-test.js +++ b/test/prototype-test.js @@ -794,7 +794,7 @@ describe("PROTOTYPES", () => { }); describe("Dinosaur Prompts", () => { - it.skip("countAwesomeDinosaurs", () => { + it("countAwesomeDinosaurs", () => { const e = dinosaurPrompts.countAwesomeDinosaurs(); expect(e).to.deep.equal({ @@ -806,7 +806,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("averageAgePerMovie", () => { + it("averageAgePerMovie", () => { const e = dinosaurPrompts.averageAgePerMovie(); expect(e).to.deep.equal({ @@ -826,7 +826,7 @@ describe("PROTOTYPES", () => { }) }); - it.skip("uncastActors", () => { + it("uncastActors", () => { const e = dinosaurPrompts.uncastActors(); expect(e).to.deep.equal([{ @@ -850,7 +850,7 @@ describe("PROTOTYPES", () => { }]) }); - it.skip("actorsAgesInMovies", () => { + it("actorsAgesInMovies", () => { const e = dinosaurPrompts.actorsAgesInMovies(); expect(e).to.deep.equal([{