diff --git a/mandatory/8-cheap-diner.js b/mandatory/10-cheap-diner.js similarity index 100% rename from mandatory/8-cheap-diner.js rename to mandatory/10-cheap-diner.js diff --git a/mandatory/9-choose-your-own-adventure.js b/mandatory/11-choose-your-own-adventure.js similarity index 100% rename from mandatory/9-choose-your-own-adventure.js rename to mandatory/11-choose-your-own-adventure.js diff --git a/mandatory/2-eligible-students.js b/mandatory/2-eligible-students.js new file mode 100644 index 00000000..ca8da426 --- /dev/null +++ b/mandatory/2-eligible-students.js @@ -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"] +); + \ No newline at end of file diff --git a/mandatory/3-journey-planner.js b/mandatory/3-journey-planner.js new file mode 100644 index 00000000..baf38b4c --- /dev/null +++ b/mandatory/3-journey-planner.js @@ -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", + ]) +); \ No newline at end of file diff --git a/mandatory/2-water-bottle.js b/mandatory/4-water-bottle.js similarity index 100% rename from mandatory/2-water-bottle.js rename to mandatory/4-water-bottle.js diff --git a/mandatory/3-groceries.js b/mandatory/5-groceries.js similarity index 100% rename from mandatory/3-groceries.js rename to mandatory/5-groceries.js diff --git a/mandatory/4-people-I-know.js b/mandatory/6-people-I-know.js similarity index 100% rename from mandatory/4-people-I-know.js rename to mandatory/6-people-I-know.js diff --git a/mandatory/5-recipes.js b/mandatory/7-recipes.js similarity index 100% rename from mandatory/5-recipes.js rename to mandatory/7-recipes.js diff --git a/mandatory/6-reading-list.js b/mandatory/8-reading-list.js similarity index 100% rename from mandatory/6-reading-list.js rename to mandatory/8-reading-list.js diff --git a/mandatory/7-budgets.js b/mandatory/9-budgets.js similarity index 100% rename from mandatory/7-budgets.js rename to mandatory/9-budgets.js