Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Merged
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
File renamed without changes.
53 changes: 53 additions & 0 deletions mandatory/2-eligible-students.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
This exercise may look familiar!
In JS1 week 3 we had an exercise called eligible-students,
where we stored each student's name and score in an array.

This is the same exercise again, but we've stored each student's
information in an object instead of an array.

After you complete the exercise, compare your solution to your previous one.
Can you see how using objects leads to more clear code?

-------------------------------------------------------------------------

Only students who have attended enough classes are eligible to sit an exam.

Create a function which:
- Accepts an array which contains all the students' names and their attendance counts
(see tests to confirm how this data will be structured)
- Returns an array containing only the names of the who have attended AT LEAST 8 classes
*/

function eligibleStudents(attendance) {
}

/* ======= TESTS - DO NOT MODIFY ===== */

const attendances = [
{name: "Ahmed", attendance: 8},
{name: "Clement", attendance: 10},
{name: "Elamin", attendance: 6},
{name: "Adam", attendance: 7},
{name: "Tayoa", attendance: 11},
{name: "Nina", attendance: 10},
];

const util = require('util');

function test(test_name, actual, expected) {
let status;
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test("eligibleStudents function works",
eligibleStudents(attendances),
["Ahmed", "Clement", "Tayoa", "Nina"]
);

87 changes: 87 additions & 0 deletions mandatory/3-journey-planner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
This exercise was also in JS1 week 3, but you didn't know about objects yet.
It's more clear with objects than with arrays!
Feel free to look at your solution to that one to help you out - you already did this once!

-----------------------------------------------------------------------

Write a function journeyPlanner that:

- Accepts two paramters:
1) An object where the keys are locations and the values are arrays of the transportation modes you can use to get there.
e.g.
{
Angel: ["tube", "bus"],
"London Bridge": ["tube", "river boat"],
}

2) A string containing a transport mode
e.g. "bus"

- Returns an array of where I can go if I only want to use a specific mode of transport.

NOTE: Only the location names should be returned, as strings.

When you finish the exercise, think about how this solution is different to your last solution.
What's better about each approach?
*/
function journeyPlanner(locations, transportMode) {
}

/* ======= TESTS - DO NOT MODIFY ===== */

const londonLocations = {
"Angel": ["tube", "bus"],
"London Bridge": ["tube", "river boat"],
"Tower Bridge": ["tube", "bus"],
"Greenwich": ["bus", "river boat"],
};

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;

for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}

return true;
}

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
}

test(
"journeyPlanner function works - case 1",
arraysEqual(journeyPlanner(londonLocations, "river boat"), [
"London Bridge",
"Greenwich",
])
);

test(
"journeyPlanner function works - case 2",
arraysEqual(journeyPlanner(londonLocations, "bus"), [
"Angel",
"Tower Bridge",
"Greenwich",
])
);

test(
"journeyPlanner function works - case 3",
arraysEqual(journeyPlanner(londonLocations, "tube"), [
"Angel",
"London Bridge",
"Tower Bridge",
])
);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.