Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Week3/patrick #83

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Completed wk3 Mandatory Q1 - Q3
  • Loading branch information
wonder woman committed Jul 2, 2020
commit 1444144048176e9011f539bff14db9120259d1e8
16 changes: 14 additions & 2 deletions week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels
Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5%
*/

/* NOTES
filter() gives you a new array
include() gives you a boolean
every() gives you a boolean
find() gives you the first value that meets the condition(s)
*/

function findRightPlanet(oxygenLevelOfPlanet) {
if (parseFloat(oxygenLevelOfPlanet) > `${19.5}%` && parseFloat(oxygenLevelOfPlanet) < `${23.5}%`) {
return `${oxygenLevelOfPlanet}%`;
Expand All @@ -18,9 +25,14 @@ function findRightPlanet(oxygenLevelOfPlanet) {
}

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
// find the first element that meets the condition and ends the test (different from filter)
// find the first element that meets the condition and ends the test (different from filter which gives you a new array)
function safeLevels(oxygenLevel) {
return oxygenLevel.find(findRightPlanet)
return oxygenLevel.find(findRightPlanet);
}

// EK's version - passed
function safeLevels(oxygen) {
return oxygen.find(level => level > "19.5%" && level < "23.5%");
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
7 changes: 7 additions & 0 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ function bushChecker(allBushBerryColours) {
}
}

// EK's version - .some function finds if any element is not 'pink'
function bushChecker(berry) {
if (berry.some(color => color !== '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"]
Expand Down
14 changes: 13 additions & 1 deletion week-3/2-mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
NOTE: don't include any element that is not a "family".
*/

function colonisers() {
// find elements that include "family" and starts with an "A"
/* my version failed
function colonisers(name) {
if (name.includes('family') && name.startsWith('A')) {
return name;
}
}

console.log(name.filter(colonisers));
*/

// EK's version modified
function colonisers(voyagersArr) {
return voyagersArr.filter(voyager => voyager.includes('family') && voyager[0] === 'A');
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
15 changes: 14 additions & 1 deletion week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
Write a function that will return all street names which contain 'Lane' in their name.
*/

function getLanes() {
// https://www.youtube.com/watch?v=iOml7u_sAVk
const streetNames = [
"Abchurch Lane",
"Adam's Court",
"Addle Hill",
"Addle Lane",
"Alban Highwalk"
]

function getLanes(streetNames) {
let result = streetNames.includes('Lane'); // returns boolean

if (result === true) {
return streetNames;
}
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
4 changes: 2 additions & 2 deletions week-3/2-mandatory/7-password-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Expected Result:
PasswordValidationResult= [false, false, false, false, true]

*/

// https://stackoverflow.com/questions/36097097/password-validate-8-digits-contains-upper-lowercase-and-a-special-character
function validatePasswords(passwords) {

passwords.length >=5;
}

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