Skip to content

RMT-JAN2025-solved #3692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
115 changes: 107 additions & 8 deletions src/clue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,124 @@

// Suspects Array

const suspectsArray = [];
const suspectsArray = [
{
firstName: "Jacob",
lastName: "Green",
occupation: "Entrepreneur",
age: 45,
description: "He has a lot of connections",
image:
"https://pbs.twimg.com/profile_images/506787499331428352/65jTv2uC.jpeg",
color: "green",
},
{
firstName: "Doctor",
lastName: "Orchid",
occupation: "Scientist",
age: 26,
description: " PhD in plant toxicology. Adopted daughter of Mr. Boddy",
image: "http//www.radiotimes.com/uploads/images/Original/111967.jpg",
color: "white",
},
{
firstName: "Victor",
lastName: "Plum",
occupation: "Designer",
age: 22,
description: "Billionaire video game designer",
image:
"https://66.media.tumblr.com/ee7155882178f73b3781603f0908617c/tumblr_phhxc7EhPJ1w5fh03_540.jpg",
color: "purple",
},
{
firstName: "Kasandra",
lastName: "Scarlet",
occupation: "Actor",
age: 31,
description: "She is an A-list movie star with a dark past",
image: "https://www.radiotimes.com/uploads/images/Original/111967.jpg",
color: "red",
},
{
firstName: "Eleanor",
lastName: "Peacock",
occupation: "Socialité",
age: 36,
description:
"She is from a wealthy family and uses her status and money to earn popularity",
image: "https://metrouk2.files.wordpress.com/2016/07/mrs-peacock.jpg",
color: "blue",
},
{
firstName: "Jack",
lastName: "Mustard",
occupation: "Retired Football player",
age: 62,
description:
"He is a former football player who tries to get by on his former glory",
image:
"https://static.independent.co.uk/s3fs-public/thumbnails/image/2016/07/04/08/unspecified-3.jpg",
color: "yellow",
},
];

// Rooms Array

const roomsArray = [];
const weaponsArray = [
{ name: "rope", weight: 10 },
{ name: "knife", weight: 8 },
{ name: "candlestick", weight: 2 },
{ name: "dumbbell", weight: 30 },
{ name: "poison", weight: 2 },
{ name: "axe", weight: 15 },
{ name: "bat", weight: 13 },
{ name: "trophy", weight: 25 },
{ name: "pistol", weight: 20 },
];

// Weapons Array

const weaponsArray = [];

const roomsArray = [
{ name: "Dining Room" },
{ name: "Conservatory" },
{ name: "Kitchen" },
{ name: "Study" },
{ name: "Library" },
{ name: "Billiard Room" },
{ name: "Lounge" },
{ name: "Ballroom" },
{ name: "Hall" },
{ name: "Spa" },
{ name: "Living Room" },
{ name: "Observatory" },
{ name: "Theater" },
{ name: "Guest House" },
{ name: "Patio" },
];

// ITERATION 2

function selectRandom() {}
function selectRandom(arr) {
let randomNum = arr[Math.floor(Math.random() * arr.length)];

function pickMystery() {}
return randomNum;
}

function pickMystery() {
let suspect = selectRandom(suspectsArray);

// ITERATION 3
let room = selectRandom(roomsArray);

let weapon = selectRandom(weaponsArray);

function revealMystery() {}
return { suspect, room, weapon };
}

// ITERATION 3

function revealMystery(mystery) {
let message = `${mystery.suspect.firstName} ${mystery.suspect.lastName} killed Mr. Boddy using the ${mystery.weapon.name} in the ${mystery.room.name}!`;
console.log(message);
return message;
}
108 changes: 54 additions & 54 deletions tests/clue.spec.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
describe("Array 'suspectsArray'", () => {
it('should be an array', () => {
it("should be an array", () => {
expect(Array.isArray(suspectsArray)).toBeTruthy();
});

it('should have 6 suspects (objects)', () => {
it("should have 6 suspects (objects)", () => {
expect(suspectsArray.length).toBe(6);
});

describe('- Suspect Objects', () => {
describe("- Suspect Objects", () => {
beforeAll(() => {
expect(suspectsArray.length).toBeTruthy();
});

it('should have a string in property "firstName"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.firstName).toBe('string');
expect(typeof suspect.firstName).toBe("string");
});

it('should have a string in property "lastName"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.lastName).toBe('string');
expect(typeof suspect.lastName).toBe("string");
});

it('should have a string in property "occupation"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.occupation).toBe('string');
expect(typeof suspect.occupation).toBe("string");
});

it('should have a number in property "age"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.age).toBe('number');
expect(typeof suspect.age).toBe("number");
});

it('should have a string in property "description"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.description).toBe('string');
expect(typeof suspect.description).toBe("string");
});

it('should have a string in property "image"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.image).toBe('string');
expect(typeof suspect.image).toBe("string");
});

it('should have a string in property "color"', () => {
for (let suspect of suspectsArray)
expect(typeof suspect.color).toBe('string');
expect(typeof suspect.color).toBe("string");
});
});
});

describe("Array 'weaponsArray'", () => {
it('should be an array', () => {
it("should be an array", () => {
expect(Array.isArray(weaponsArray)).toBeTruthy();
});

it('should have 9 weapons (objects)', () => {
it("should have 9 weapons (objects)", () => {
expect(weaponsArray.length).toBe(9);
});

describe('- Weapon Objects', () => {
describe("- Weapon Objects", () => {
beforeAll(() => {
expect(weaponsArray.length).toBeTruthy();
});

it('should have a string in property "name"', () => {
for (let weapon of weaponsArray)
expect(typeof weapon.name).toBe('string');
expect(typeof weapon.name).toBe("string");
});

it('should have a number in property "weight"', () => {
for (let weapon of weaponsArray)
expect(typeof weapon.weight).toBe('number');
expect(typeof weapon.weight).toBe("number");
});
});
});

describe("Array 'roomsArray'", () => {
it('should be an array', () => {
it("should be an array", () => {
expect(Array.isArray(roomsArray)).toBeTruthy();
});

it('should have 15 rooms (objects)', () => {
it("should have 15 rooms (objects)", () => {
expect(roomsArray.length).toBe(15);
});

describe('- Room Objects', () => {
describe("- Room Objects", () => {
beforeAll(() => {
expect(roomsArray.length).toBeTruthy();
});

it('should have a string in property "name"', () => {
for (let room of roomsArray) expect(typeof room.name).toBe('string');
for (let room of roomsArray) expect(typeof room.name).toBe("string");
});
});
});

describe('Function "selectRandom" - Find a random element of the array', () => {
it('should be declared', () => {
expect(typeof selectRandom).toBe('function');
it("should be declared", () => {
expect(typeof selectRandom).toBe("function");
});

it("should return undefined if the array is empty", () => {
Expand All @@ -108,92 +108,92 @@ describe('Function "selectRandom" - Find a random element of the array', () => {
expect(selectRandom(["ab"])).toBe("ab");
});

it('should return an element of the array', () => {
const array = ['ab', 'zz', 'zx', 'zy'];
it("should return an element of the array", () => {
const array = ["ab", "zz", "zx", "zy"];
expect(array.includes(selectRandom(array))).toBeTruthy();
});

it('should return a random element of the array', () => {
const mathRandomSpy = spyOn(Math, 'random');
it("should return a random element of the array", () => {
const mathRandomSpy = spyOn(Math, "random");

mathRandomSpy.and.returnValue(0.5);

expect(
selectRandom(['a', 'ab', 'abb', 'aab', 'aaa', 'sda', 'kas'])
).toEqual('aab');
selectRandom(["a", "ab", "abb", "aab", "aaa", "sda", "kas"])
).toEqual("aab");

mathRandomSpy.and.returnValue(0.1);
expect(
selectRandom(['a', 'ab', 'abb', 'aab', 'aaa', 'sda', 'kas'])
).toEqual('a');
selectRandom(["a", "ab", "abb", "aab", "aaa", "sda", "kas"])
).toEqual("a");

mathRandomSpy.and.returnValue(0.9);
expect(
selectRandom(['a', 'ab', 'abb', 'aab', 'aaa', 'sda', 'kas'])
).toEqual('kas');
selectRandom(["a", "ab", "abb", "aab", "aaa", "sda", "kas"])
).toEqual("kas");
});
});

describe('Function "pickMystery" - Pick a random mystery', () => {
it('should be declared', () => {
expect(typeof pickMystery).toBe('function');
it("should be declared", () => {
expect(typeof pickMystery).toBe("function");
});

it('should return an object', () => {
it("should return an object", () => {
const mistery = pickMystery();

expect(typeof mistery).toEqual('object');
expect(typeof mistery).toEqual("object");
expect(mistery !== null).toBeTruthy();
});

it('should return an object with 3 properties: `suspect`, `weapon`, `room`', () => {
it("should return an object with 3 properties: `suspect`, `weapon`, `room`", () => {
const mistery = pickMystery();

expect(Object.keys(mistery).length).toBe(3);
expect(Object.keys(mistery)).toContain('suspect');
expect(Object.keys(mistery)).toContain('weapon');
expect(Object.keys(mistery)).toContain('room');

expect(Object.keys(mistery)).toContain("suspect");
expect(Object.keys(mistery)).toContain("weapon");
expect(Object.keys(mistery)).toContain("room");
});

it('should return a suspect in the suspect property of the object', () => {
it("should return a suspect in the suspect property of the object", () => {
const mistery = pickMystery();
expect(suspectsArray.includes(mistery.suspect)).toBeTruthy();
});

it('should return a weapon in the weapon property of the object', () => {
it("should return a weapon in the weapon property of the object", () => {
const mistery = pickMystery();
expect(weaponsArray.includes(mistery.weapon)).toBeTruthy();
});

it('should return a room in the room property of the object', () => {
it("should return a room in the room property of the object", () => {
const mistery = pickMystery();
expect(roomsArray.includes(mistery.room)).toBeTruthy();
});
});

describe('Function "revealMystery" - Reveal the mystery', () => {
it('should define revealMystery', () => {
expect(typeof revealMystery).toBe('function');
it("should define revealMystery", () => {
expect(typeof revealMystery).toBe("function");
});

it('should return a string', () => {
it("should return a string", () => {
const message = revealMystery({
suspect: { firstName: 'aa', lastName: 'abc' },
weapon: { name: 'abd' },
room: { name: 'abb' }
suspect: { firstName: "aa", lastName: "abc" },
weapon: { name: "abd" },
room: { name: "abb" },
});
expect(typeof message).toEqual('string');
expect(typeof message).toEqual("string");
});

it('should return "<FIRST NAME> <LAST NAME> killed Mr. Boddy using the <WEAPON> in the <PLACE>!"', () => {
const message = revealMystery({
suspect: { firstName: 'Victor', lastName: 'Plum' },
weapon: { name: 'poison' },
room: { name: 'Billiard Room' }
suspect: { firstName: "Victor", lastName: "Plum" },
weapon: { name: "poison" },
room: { name: "Billiard Room" },
});
expect(message).toEqual(
'Victor Plum killed Mr. Boddy using the poison in the Billiard Room!'
"Victor Plum killed Mr. Boddy using the poison in the Billiard Room!"
);
});
});