From d6056d8bd7150384057f8f126c5fa373a3e6f16e Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Fri, 3 Jul 2020 15:22:59 +0100 Subject: [PATCH 01/12] oxygen-levels --- week-3/2-mandatory/1-oxygen-levels.js | 52 +++++++++++++-------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index f9d745f..77b10a4 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -1,7 +1,7 @@ /* Many years into the future, a team of Space Voyagers find their ship is low on Oxygen and need to dock somewhere safe while they call home for help. - + Their computer detects a list of nearby planets that have Oxygen in their atmosphere. It has produced an array of their Oxygen levels. To be safe to land on, a planet needs to have an Oxygen level between 19.5% and 23.5%. @@ -9,8 +9,14 @@ To be safe to land on, a planet needs to have an Oxygen level between 19.5% and Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5% */ -function safeLevels() { +function safeLevels(oxygenLevel) { + for (let i =0; i< oxygenLevel.length; i++) { + oxygenLevel[i] = parseFloat(oxygenLevel[i]); + if (oxygenLevel[i] > 19.5 && oxygenLevel[i] < 23.5) { + return `${oxygenLevel[i]}%`; + } + } } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -19,33 +25,23 @@ const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"]; const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"]; const oxygenLevels3 = ["200%", "21.1%"]; -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; + } + + console.log(`${test_name}: ${status}`); } -test( - "safeLevels function works - case 1", - safeLevels(oxygenLevels1), - "19.9%" -); - -test( - "safeLevels function works - case 2", - safeLevels(oxygenLevels2), - "20.2%" -); - -test( - "safeLevels function works - case 3", - safeLevels(oxygenLevels3), - "21.1%" -); +test("safeLevels function works - case 1", safeLevels(oxygenLevels1), "19.9%"); + +test("safeLevels function works - case 2", safeLevels(oxygenLevels2), "20.2%"); + +test("safeLevels function works - case 3", safeLevels(oxygenLevels3), "21.1%"); From ecda7f65df847661d29fcf0a3f600ed2a6a8a112 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Sat, 4 Jul 2020 00:44:47 +0100 Subject: [PATCH 02/12] bush berry --- week-3/2-mandatory/2-bush-berries.js | 33 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index aca45ad..c0436ff 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,26 +10,33 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(items) { + for (let item of items) { + if (item !== 'pink') { + return "Toxic! Leave bush alone!"; + } + } + return "Bush is safe to eat from"; } /* ======= TESTS - DO NOT MODIFY ===== */ -let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"] -let bushBerryColours2 = ["pink", "pink", "pink", "pink"] +let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]; +let bushBerryColours2 = ["pink", "pink", "pink", "pink"]; -const util = require('util'); +const util = require("util"); function test(test_name, actual, expected) { - let status; - if (actual === expected) { - status = "PASSED"; - } else { - status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; - } - - console.log(`${test_name}: ${status}`); + let status; + if (actual === expected) { + status = "PASSED"; + } else { + status = `FAILED: expected: ${util.inspect( + expected + )} but your function returned: ${util.inspect(actual)}`; + } + + console.log(`${test_name}: ${status}`); } test( From 6c2e7b322c5e466cb6344d798be3652bb8d285cd Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Sat, 4 Jul 2020 00:55:03 +0100 Subject: [PATCH 03/12] space colonies --- week-3/2-mandatory/3-space-colonies.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index 239eddd..68cc952 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,8 +8,14 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - +function colonisers(names) { + let newNames = []; + for (let i = 0; i < names.length; i++) { + if (names[i][0] === 'A' && names[i].includes('family')) { + newNames.push(names[i]); + } + } + return newNames; } /* ======= TESTS - DO NOT MODIFY ===== */ From f011042cea32c479c4783d002d6bd00c424fed5b Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Sat, 4 Jul 2020 01:12:13 +0100 Subject: [PATCH 04/12] eligible students --- week-3/2-mandatory/4-eligible-students.js | 44 ++++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index d8fe052..876ec8f 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,8 +7,14 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(student) { + let attendMinClasses = []; + for (let i = 0; i < student.length; i++) { + if (student[i][1] >= 8) { + attendMinClasses.push(student[i][0]); + } + } + return attendMinClasses; } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -19,23 +25,27 @@ const attendances = [ ["Elamin", 6], ["Adam", 7], ["Tayoa", 11], - ["Nina", 10] -] + ["Nina", 10], +]; -const util = require('util'); +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}`); + 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"] -); +test("eligibleStudents function works", eligibleStudents(attendances), [ + "Ahmed", + "Clement", + "Tayoa", + "Nina", +]); From 1406d0e1c750eb89cc062762d5c8a03396f8a612 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Mon, 6 Jul 2020 01:06:49 +0100 Subject: [PATCH 05/12] journey-planner --- week-3/2-mandatory/5-journey-planner.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 816637d..2950d07 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,7 +7,14 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(locationsArr, transport) { + let newArr = []; + for (let i=0; i Date: Mon, 6 Jul 2020 01:18:01 +0100 Subject: [PATCH 06/12] Lane-names --- week-3/2-mandatory/6-lane-names.js | 51 +++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index ef4e1c5..54915a4 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,35 +4,42 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(streets) { + let streetWithLane = []; + for (let street of streets) { + if (street.includes("Lane")) { + streetWithLane.push(street); + } + } + return streetWithLane; } /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ - "Abchurch Lane", - "Adam's Court", - "Addle Hill", - "Addle Lane", - "Alban Highwalk" -] + "Abchurch Lane", + "Adam's Court", + "Addle Hill", + "Addle Lane", + "Alban Highwalk", +]; -const util = require('util'); +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}`); + 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( - "getLanes function works", - getLanes(streetNames), - ["Abchurch Lane", "Addle Lane"] -); +test("getLanes function works", getLanes(streetNames), [ + "Abchurch Lane", + "Addle Lane", +]); From e7adbb3d7e79ed04ef0df0ab36fad889e47848e7 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Mon, 6 Jul 2020 23:10:31 +0100 Subject: [PATCH 07/12] E-array-map --- week-3/1-exercises/E-array-map/exercise.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/week-3/1-exercises/E-array-map/exercise.js b/week-3/1-exercises/E-array-map/exercise.js index 2835e92..cdf93f5 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -2,4 +2,21 @@ // Write multiple solutions using different syntax (as shown in the README) var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +let numbersByHundred = function (number) { + return number * 100; +}; +let result = numbers.map(numbersByHundred); +console.log(result); +let numbersHundred = numbers.map(function hundred(number) { + return number * 100; +}); +console.log(numbersHundred); + +let numHundred = numbers.map(function (number) { + return number * 100; +}); +console.log(numHundred); + +let byHundred = numbers.map(number => number * 100); +console.log(byHundred); From 4540ca9c30557dbf21e0bb922494ded793065c86 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Mon, 6 Jul 2020 23:10:58 +0100 Subject: [PATCH 08/12] Update exercise.js --- week-3/1-exercises/D-array-filter/exercise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 6e32cc6..88a4103 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,12 +8,12 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +var pairsByIndex// Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; -var pairs = pairsByIndex.map(function(indexes) { +var pairs = pairsByIndex.map(function (indexes) { var student = students[indexes[0]]; var mentor = mentors[indexes[1]]; return [student, mentor]; From 4e35b6aaa6ae3ff329f899a946b7d6600e4d93ea Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Thu, 9 Jul 2020 01:11:24 +0100 Subject: [PATCH 09/12] A-array-find --- week-3/1-exercises/A-array-find/exercise.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..3934f7c 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -7,9 +7,10 @@ var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; -var longNameThatStartsWithA = findLongNameThatStartsWithA(names); - -console.log(longNameThatStartsWithA); +var nameFound = names.find(function longNamesA (name) { + return name.length >7 && name[0]==='A'; +}); +console.log(nameFound); /* EXPECTED OUTPUT */ // "Alexandra" From 40ece9c3b9c60d098abee2469d39fd8ad1bb79d4 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Thu, 9 Jul 2020 02:39:48 +0100 Subject: [PATCH 10/12] C-array-every --- week-3/1-exercises/B-array-some/README.md | 2 +- week-3/1-exercises/B-array-some/exercise.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/week-3/1-exercises/B-array-some/README.md b/week-3/1-exercises/B-array-some/README.md index ecfcac4..794417d 100644 --- a/week-3/1-exercises/B-array-some/README.md +++ b/week-3/1-exercises/B-array-some/README.md @@ -6,7 +6,7 @@ var numbers = [1, 3, -1, 5, 9]; You know that the array is supposed to contain positive numbers, but you want to check if it also contains any negative numbers. -We can write a function that checks this: +We can write a function that checks this: ```js function isNegative(number) { diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..04058c0 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -20,5 +20,10 @@ var pairs = pairsByIndex.map(function(indexes) { var mentor = mentors[indexes[1]]; return [student, mentor]; }); - -console.log(pairs); +function isNull(pair) { + if (typeof pair === 'null'){ + process.exit(1); + } +} +let result = pairsByIndex.some(isNull(pairs)) +console.log(result); From 6347a364b797a96e615636d8b41da93ec206d3ac Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Thu, 9 Jul 2020 02:51:04 +0100 Subject: [PATCH 11/12] exericises --- week-3/1-exercises/C-array-every/exercise.js | 3 ++- week-3/1-exercises/D-array-filter/exercise.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..c0bb00f 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -5,7 +5,8 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement + +var groupIsOnlyStudents = group.every(test => students.includes(test)); // complete this statement if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 88a4103..2ad8638 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,9 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex// Complete this statement +var pairsByIndex = pairsByIndexRaw.filter(function(value){ + return ; +});// Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; From c94f1abfdb283bbdf4bf4407a5ce65dc36e35138 Mon Sep 17 00:00:00 2001 From: Jacques Vertommen Date: Thu, 9 Jul 2020 03:10:24 +0100 Subject: [PATCH 12/12] Delete exercise.js --- week-3/1-exercises/B-array-some/exercise.js | 29 --------------------- 1 file changed, 29 deletions(-) delete mode 100644 week-3/1-exercises/B-array-some/exercise.js diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js deleted file mode 100644 index 04058c0..0000000 --- a/week-3/1-exercises/B-array-some/exercise.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - You are given a program that logs pairings between mentors and students - It fails because the array `pairsById` can contain null values - It is decided that if there is a null value the program should exit - - Add a check for null values, and if one exists, exit the program - - Do not edit any of the existing code -*/ - -var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; - -// If there is a null value in the array exit the program with the error code -// https://nodejs.org/api/process.html#process_process_exit_code -// process.exit(1); - -var students = ["Islam", "Lesley", "Harun", "Rukmini"]; -var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; - -var pairs = pairsByIndex.map(function(indexes) { - var student = students[indexes[0]]; - var mentor = mentors[indexes[1]]; - return [student, mentor]; -}); -function isNull(pair) { - if (typeof pair === 'null'){ - process.exit(1); - } -} -let result = pairsByIndex.some(isNull(pairs)) -console.log(result);