Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 4.student-exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const getTrainersAndGymsAndPokemons = (gyms, trainers, pokemons) => {
// Your code here
};

const getPsychicTrainersAndGyms = (gyms, trainers, pokemons) => {
// Your code here
};

const getGymsWithPokemons = (gyms, trainers, pokemons, ...pokemonsToFind) => {
// Your code here
};

module.exports = {
getPsychicTrainersAndGyms,
getTrainersAndGymsAndPokemons,
getGymsWithPokemons
};
71 changes: 71 additions & 0 deletions 4.student-exercises.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const pokemons = require("./pokeData");
const trainers = require("./trainerData");
const gyms = require("./gymData");

const {
getPsychicTrainersAndGyms,
getTrainersAndGymsAndPokemons,
getGymsWithPokemons
} = require("./4.student-exercises");

test("getTrainersAndGymsAndPokemons", () => {
const trainersAndGymsAndPokemons = getTrainersAndGymsAndPokemons(
gyms,
trainers,
pokemons
);
expect(trainersAndGymsAndPokemons.length).toBe(9);
expect(trainersAndGymsAndPokemons.map(trainer => trainer.gym)).toEqual(
expect.any(Object)
);
expect(trainersAndGymsAndPokemons.map(trainer => trainer.pokemons)).toEqual(
expect.any(Array)
);
});

test(`getPsychicTrainersAndGyms: expect a list of trainers with psychic pokemons.
also include (all) their pokemons and their gym`, () => {
const result = getPsychicTrainersAndGyms(gyms, trainers, pokemons);
expect(result.length).toEqual(2);
expect(result[0].name).toBe("Sabrina");
expect(result[1].name).toBe("Misty");
expect(result[0].gym).toEqual(expect.any(Object));
expect(result[1].gym).toEqual(expect.any(Object));
expect(result[0].gym.city).toBe("Saffron City");
expect(result[1].gym.city).toBe("Cerulean City");
expect(result[0].pokemons).toEqual(expect.any(Array));
expect(result[1].pokemons).toEqual(expect.any(Array));
expect(result[0].pokemons.length).toBe(4);
expect(result[1].pokemons.length).toBe(2);
});

test("getGymsWithPokemons: expect a list of gyms where certain pokemons can be found", () => {
const result = getGymsWithPokemons(
gyms,
trainers,
pokemons,
"Gloom",
"Starmie"
);
result.forEach(pokemon => {
expect(pokemon).toEqual(
expect.objectContaining({
id: expect.any(Number),
name: expect.any(String),
trainers: expect.any(Array),
gyms: expect.any(Array)
})
);
});
expect(result.length).toEqual(2);
expect(result[0].trainers.length).toEqual(2);
expect(result[1].trainers.length).toEqual(1);
expect(result[0].trainers[0].name).toBe("Brock");
expect(result[0].trainers[1].name).toBe("Erika");
expect(result[1].trainers[0].name).toBe("Misty");
expect(result[0].gyms.length).toEqual(2);
expect(result[1].gyms.length).toEqual(1);
expect(result[0].gyms[0].city).toBe("Celadon City");
expect(result[0].gyms[1].city).toBe("Pewter City");
expect(result[1].gyms[0].city).toBe("Cerulean City");
});
18 changes: 9 additions & 9 deletions gymData.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = [
{ id: 1, city: 'Saffron City', trainerId: 2 },
{ id: 2, city: 'Fuchsia City', trainerId: 3 },
{ id: 3, city: 'Cinnabar Island', trainerId: 5 },
{ id: 4, city: 'Celadon City ', trainerId: 7 },
{ id: 5, city: 'Cerulean City', trainerId: 8 },
{ id: 6, city: 'Vermilion City', trainerId: 6 },
{ id: 7, city: 'Pewter City', trainerId: 1 },
{ id: 8, city: 'Viridian City', trainerId: 4 },
]
{ id: 1, city: "Saffron City", trainerId: 2 },
{ id: 2, city: "Fuchsia City", trainerId: 3 },
{ id: 3, city: "Cinnabar Island", trainerId: 5 },
{ id: 4, city: "Celadon City", trainerId: 7 },
{ id: 5, city: "Cerulean City", trainerId: 8 },
{ id: 6, city: "Vermilion City", trainerId: 6 },
{ id: 7, city: "Pewter City", trainerId: 1 },
{ id: 8, city: "Viridian City", trainerId: 4 }
];
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "data-transformations",
"version": "1.0.0",
"description": "A set of exercises for the data transformation day",
"main": "index.js",
"scripts": {
"test": "jest --watch",
"exercise1": "jest 1.map-filter-find.test --watch",
"exercise2": "jest 2.reduce.test --watch",
"exercise3": "jest 3.data-mining.test --watch"
},
"author": "Codaisseur",
"license": "ISC",
"devDependencies": {
"jest": "^24.7.1"
}
}
"name": "data-transformations",
"version": "1.0.0",
"description": "A set of exercises for the data transformation day",
"main": "index.js",
"scripts": {
"test": "jest --watch",
"exercise1": "jest 1.map-filter-find.test --watch",
"exercise2": "jest 2.reduce.test --watch",
"exercise3": "jest 3.data-mining.test --watch",
"exercise4": "jest 4.student-exercises.test --watch"
},
"author": "Codaisseur",
"license": "ISC",
"devDependencies": {
"jest": "^24.7.1"
}
}
20 changes: 10 additions & 10 deletions trainerData.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = [
{ id: 1, name: 'Brock', pokemonIds: [74, 95] },
{ id: 2, name: 'Sabrina', pokemonIds: [64, 122, 49, 65] },
{ id: 3, name: 'Koga', pokemonIds: [109, 110, 109, 89] },
{ id: 4, name: 'Giovanni', pokemonIds: [112, 51, 31, 34, 113] },
{ id: 5, name: 'Blaine', pokemonIds: [58, 77, 78, 59] },
{ id: 6, name: 'Lt. Surge', pokemonIds: [100, 25, 26] },
{ id: 7, name: 'Erika', pokemonIds: [71, 114, 44] },
{ id: 8, name: 'Misty', pokemonIds: [120, 121] },
{ id: 9, name: 'Ash', pokemonIds: [25, 1, 7, 6, 17, 12] },
]
{ id: 1, name: "Brock", pokemonIds: [74, 95, 44] },
{ id: 2, name: "Sabrina", pokemonIds: [64, 122, 49, 65] },
{ id: 3, name: "Koga", pokemonIds: [109, 110, 109, 89] },
{ id: 4, name: "Giovanni", pokemonIds: [112, 51, 31, 34, 113] },
{ id: 5, name: "Blaine", pokemonIds: [58, 77, 78, 59] },
{ id: 6, name: "Lt. Surge", pokemonIds: [100, 25, 26] },
{ id: 7, name: "Erika", pokemonIds: [71, 114, 44] },
{ id: 8, name: "Misty", pokemonIds: [120, 121] },
{ id: 9, name: "Ash", pokemonIds: [25, 1, 7, 6, 17, 12] }
];